【发布时间】:2014-07-27 12:54:21
【问题描述】:
当我使用 jboss 7.1 在 jsf 2.2 项目中上传文件时 它阻止提交表单。 帮帮我....
这是上传文件的示例代码
这是我的welcome.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>
<h:form enctype="multipart/form-data" >
<h:outputLabel value="Upload File : " />
<h:inputFile value="#{myController.file}"/>
<h:commandButton value="Submit" action="#{myController.mycontroller}" />
</h:form>
</h:body>
</html>
这是我的支持 bean MyController.java
public class MyController {
private Part file;
public Part getFile() {
return file;
}
public void setFile(Part file) {
this.file = file;
}
public String mycontroller() throws IOException {
System.out.println("--call mycontroller method--");
UploadFile uf = new UploadFile();
boolean b = uf.upload(getFile());
System.out.println(b);
return "success.xhtml";
}
}
编辑:1
我有一个带有文件上传的表格和一个<h:commandButton>,我想在其中获取上传文件的信息。我面临的问题,当我添加enctype="multipart/form-data" 时按钮没有触发。所以任何建议都会对我有所帮助。
【问题讨论】:
-
你的问题不清楚。
标签: jsf file-upload jboss7.x jsf-2.2