jsf form enctype="multipart/form-data" 问题

hemhem 2010-02-03 03:45:07
如果form 加上enctype="multipart/form-data" 后点提交没反应,就直接刷新了一下页面,ACTION对应的东西都没做,连表单验证都没做。 如果去掉 这段后都是可以的,我主要是想做文件上传,用的是MYFACES-EXTENSION ,
<t:inputFileUpload id="txtFile" value="#{productBean.myFile}" required="true" storage="file" </t:inputFileUpload>
用的是这个。
是不是过滤器有冲突?
org.ajax4jsf.Filter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
org.apache.myfaces.component.html.util.ExtensionsFilter
我用到这么几个过滤器。
框架用到JSF,SPRING,HAIBERNATE
...全文
191 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaobing1988 2010-10-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hemhem 的回复:]
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib……
wwwwwwww[/Quote]aaaaa
hemhem 2010-02-03
  • 打赏
  • 举报
回复
问题已经解决,感谢大家关注。
原来是我的
<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
这段写错了, mapping 的NAME 少了个空格,没对应我的JSF servlet
hemhem 2010-02-03
  • 打赏
  • 举报
回复
现在关键是根本没提交上来,如果提交上来的话读就好办了。
bobo415 2010-02-03
  • 打赏
  • 举报
回复
做文件上传 用多媒体的类型提交 会有这些问题的
有封装好的包可以读取 多媒体类型提交上来的数据
hemhem 2010-02-03
  • 打赏
  • 举报
回复
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="t"%>
<html>
<head>
<title>Main Page</title>
</head>
<body>
<f:view>
<h:form id="myForm" enctype="multipart/form-data">
<h:inputText id="txtMytext" value="#{productBean.imageResult}"
required="true"> </h:inputText>
<h:message for="txtMytext"></h:message>
<t:inputFileUpload id="txtFile" value="#{productBean.myFile}"
required="true"
storage="file" ></t:inputFileUpload>
<t:message for="txtFile"></t:message>
<h:commandButton id="cmd" action="#{productBean.saveProduct}" value="submit"></h:commandButton>
</h:form>
</f:view>
</body>
</html>
HTML 页面
Asdcer 2010-02-03
  • 打赏
  • 举报
回复
想看看你形成的html页面的form部分代码
hemhem 2010-02-03
  • 打赏
  • 举报
回复
如果只用到JSF 框架是没问题的
plplum 2010-02-03
  • 打赏
  • 举报
回复
不做web好久
依赖的文件: tomahawk-1.1.3.jar commons-fileupload-1.2.jar commons-io-1.3.1.jar Tomahawk.tld 把这个三个包放在/WEB_INF/lib目录下面。Jsf依赖的包也放在这个目录下面 Tomahawk.tld放在/WEB-INF目录下。Jsf标签也放在这个目录下面。 这个主要讲jsf上传文件,因此只罗列了上传文件用到的包和标签。 Web-xml文件如下: <?xml version="1.0" encoding="UTF-8"?> javax.faces.STATE_SAVING_METHOD client <!-- Context Listener creates and sets the application handler --> <!-- Faces Servlet --> Faces Servlet javax.faces.webapp.FacesServlet 1 <!-- Faces Servlet Mapping --> Faces Servlet *.jsf ExtensionsFilter org.apache.myfaces.component.html.util.ExtensionsFilter uploadMaxFileSize 10m uploadThresholdSize 100k ExtensionsFilter 中的一致--> Faces Servlet index.html 上传文件的页面如下: <%@ include file="tags.jsp"%> form id="MyForm" enctype="multipart/form-data" > form> 其中tags.jsp文件如下: <%@ page language="java" pageEncoding="GB18030"%> <%@ page contentType="text/html" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="x"%> Faces-config.xml文件如下: myBean fileupload.MyBean request MyBean如下: package com.dhc; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.InputStream; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import org.apache.myfaces.custom.fileupload.UploadedFile; public class oaMailMainForm { private UploadedFile myFile; public UploadedFile getMyFile() { return myFile; } public void setMyFile(UploadedFile myFile) { this.myFile = myFile; } public String uploadedfile() { System.out.println("Entry"); try { InputStream in = new BufferedInputStream(myFile.getInputStream()); try { byte[] buffer = new byte[64 * 1024]; FileOutputStream fileOutputStream = new FileOutputStream( "C:\\My Files\\tst.jpg");// 这里可以把上传的文件写服务器目录,或者数据库中 while (in.read(buffer) > 0) { fileOutputStream.write(buffer); } } finally { in.close(); } System.out.println("End"); return "success"; } catch (Exception x) { System.out.print("Exception"); FacesMessage message = new FacesMessage( FacesMessage.SEVERITY_FATAL, x.getClass().getName(), x .getMessage()); FacesContext.getCurrentInstance().addMessage(null, message); return null; } } } 参考文献:http://www.blogjava.net/cooky/archive/2007/10/02/150176.html http://blog.csdn.net/meteorlWJ/archive/2008/01/09/2032505.aspx http://tml808.javaeye.com/blog/166853

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧