JSF上传时,form得设置为enctype="multipart/form-data"
但是这样设置后,点提交后form根本不提交。
上传组件用的是myfaces.
怎么办?初学jsf,希望大家多给我帮助!
但是这样设置后,点提交后form根本不提交。
上传组件用的是myfaces.
怎么办?初学jsf,希望大家多给我帮助!
解决方案 »
- 如何用同一个变量去接收jsp页面提交form传过来的字符串和servlet中request传过来的字符串
- 如何对oracle jdbc执行的每条sql语句进行检测?
- 请问高手们一个extjs editgrid 和 combobox的问题,老问题的.但是我从网上找的资料解决不了我的为难题
- Struts中Action的一点小知识
- org.apache.catalina.core.ContainerBase.
- jboss下怎么发布一个application,注意:不是web application
- 怯怯的问个j2ee 安装的问题
- dom读xml文件的问题
- APACHE2.0.54+TOMCAT5.0.28整合后URL传递中文参数问题
- Sysbase的JDBC驱动程序遍历结果集怎么这么慢,什么地方配置不对吗?
- 有开发企业级或大型网站的高手请进:请教 XML序列化(XML serialization) 和 RMI 问题
- spring如何来管理jsf请高手指点
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<f:view>
<h:form enctype="multipart/form-data" id="fileform">
<h:messages globalOnly="true"/>
File:
<x:inputFileUpload value="#{MyBean.myfile}" storage="file" />
<br>
Parem:
<h:selectOneMenu id="myParamId" value="#{MyBean.myParam}">
<f:selectItem itemLabel="" itemValue=""/>
<f:selectItem itemLabel="MD5" itemValue="MD5"/>
<f:selectItem itemLabel="SHA-1" itemValue="SHA-1"/>
<f:selectItem itemLabel="SHA-256" itemValue="SHA-256"/>
<f:selectItem itemLabel="SHA-384" itemValue="SHA-384"/>
<f:selectItem itemLabel="SHA-512" itemValue="SHA-512"/>
</h:selectOneMenu>
<br>
<h:commandButton value="提交" action="#{MyBean.processMyFile}"/>
</h:form>
</f:view>
</body>
</html>
faces-config.xml:
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>MyBean</managed-bean-name>
<managed-bean-class>bean.MyBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/upload.jsp</from-view-id>
<navigation-case>
<from-outcome>OK</from-outcome>
<to-view-id>/MyResult.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
MyBean.java
package bean;import java.io.BufferedInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.apache.myfaces.custom.fileupload.UploadedFile;/**
*
* @author HEYUN
*/
public class MyBean
{ private UploadedFile myfile;
private String myResult;
private String myParam;
/** Creates a new instance of MyBean */
public MyBean()
{
} public UploadedFile getMyfile()
{
return myfile;
} public void setMyfile(UploadedFile myfile)
{
this.myfile = myfile;
}
public String getMyParam()
{
return myParam;
} public void setMyParam(String myParam)
{
this.myParam = myParam;
}
public String getMyResult()
{
return myResult;
} public void setMyResult(String myResult)
{
this.myResult = myResult;
} public String processMyFile()
{
try
{
MessageDigest md = MessageDigest.getInstance(this.getMyParam());
InputStream in = new BufferedInputStream(myfile.getInputStream());
try
{
byte[] buffer = new byte[64 * 1024]; int count;
while ((count = in.read(buffer)) > 0) md.update(buffer, 0, count); }
} finally
{
in.close();
} byte hash[] = md.digest(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < hash.length; i++)
{
int b = hash[i] & 0xFF;
int c = (b >> 4) & 0xF;
c = c < 10 ? ('0' + c) : ('A' + c - 10);
buf.append((char) c);
c = b & 0xF;
c = c < 10 ? '0' + c : 'A' + c - 10;
buf.append((char) c);
} myResult = buf.toString(); return "OK";
} catch (Exception x)
{
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_FATAL,
x.getClass().getName(), x.getMessage());
FacesContext.getCurrentInstance().addMessage(null, message);
return null;
}
}
}enctype="multipart/form-data"加上这个根本不走这个方法MyResult.jsp 就不贴了,就是用来显示myResult 的.
而不是手动身里面添值试下。
我试了,提交按钮就是没有反应!
能再详细一点吗?