我想用 JSF 将 Excel 文件上传到 JBoss 服务器,所以我使用了 Tomahawk。
<%@ taglib uri="http:// myfaces.apache.org/tomahawk" prefix="t" %>
<h:form id="MF" enctype="multipart/form-data" >
<t:inputFileUpload id="fileupload" value="#{dataentryctl.minvoice}" storage="file" required="false" />
<h:commandButton id="Submit" type="button" action="#{dataentryctl.ProcessData}" value="save"
onclick="revalidateF12();submitForm()" onkeydown="keyDownEvents(this)" />
</h:form>
我有以下 JAR:
tomahawk-1.1.9.jar
commons-el-1.0.jar
commons-logging-1.1.1.jar
commons-fileupload-1.2.2-javadoc.jar
commons-io-1.4.jar
其他与 JSF 相关的 JAR 已经存在。其他 JSP 页面工作正常。
我也添加了 web.xml(我在启动 jBoss 服务器时没有收到任何错误)
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<description> ... </description><param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<description> ...</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>extensionsFilter</filter-name><url-pattern>.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name><url-pattern>/faces/</url-pattern>
</filter-mapping>
动作类包 panaceaFACweb.FACCtlbean;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class dataentryctl {
private UploadedFile minvoice;
public UploadedFile getMinvoice() {
return minvoice;
}
public void setMinvoice(UploadedFile minvoice) {
this.minvoice = minvoice;
}
public String ProcessData() {
load();
return null;
}
public void load() {
try {
InputStream input = minvoice.getInputStream();
// ...
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}
请帮我修复它,我尝试了一个多星期:(