我尝试使用rich:fileupload组件上传文件。当我尝试上传文件时,会出现错误, 错误是
Aug 24, 2011 9:41:19 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:140)
at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:764)
at javax.faces.component.UIInput.decode(UIInput.java:719)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1006)
at javax.faces.component.UIInput.processDecodes(UIInput.java:633)
at javax.faces.component.UIForm.processDecodes(UIForm.java:203)
at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:679)
请帮我解决此问题。
答案 0 :(得分:1)
堆栈跟踪暗示您正在使用RichFaces 3.3和Tomahawk 1.x.两个组件库都提供文件上载组件,并使用特殊的Filter
从请求正文中提取上载的文件。堆栈跟踪显示Tomahawk正在解析 RichFaces之前的请求正文。
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
...
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
一旦解析了请求正文,就无法解析它。因此,RichFaces无法从请求正文中提取上载的文件。你所面对的NullPointerException
只是不可预见的结果(RichFaces的人应该抛出一个更明确的异常,类似于IllegalStateException
,其中包含“请求中缺少上载文件”的消息身体“或喜欢,但ala)。
如果您想使用RichFaces文件上传功能,那么您必须从web.xml
中删除Tomahawk的ExtensionsFilter
。您只会错过特定look'n'feel组件的<t:inputFileUpload>
功能和一些次要功能(脚本/样式表)。其他战斧组件应保持正常工作。
答案 1 :(得分:0)
RichFaces 3.3文件上传正在运行 按照这一步。
Add this in your page:
<rich:fileUpload id="fileupload" addControlLabel="Browse" required="true"
fileUploadListener="#{ demoForm.listener}" acceptedTypes="xml"
ontyperejected="alert('Only xml files are accepted');"
maxFilesQuantity="1" listHeight="57px" listWidth="100%" disabled="#{demoForm.disabled}" >
<a4j:support event="onclear" action="#{ demoForm.clearUploadData}" reRender="fileupload" />
</rich:fileUpload>
的FormBean:
/**
*
* @param event
* @throws Exception
*/
public void listener(UploadEvent event) throws Exception{
UploadItem item = event.getUploadItem();
FileUpload file = new FileUpload();
file.setLength(item.getData().length);
file.setFile(item.getData());
file.setName(item.getFileName());
files.add(file);
}
/**
*
* @return
*/public String clearUploadData() {
files.clear();
setUploadsAvailable(1);
return null;
}
在web.xml中添加此内容
<!-- Richfaces fileupload-->
<filter>
<!-- Parameters used by rich file upload -->
<init-param>
<param-name>createTempFiles</param-name>
<param-value>false</param-value>
</init-param>
<!-- configurable property of rich:fileUpload to set maximum allowed file size, currently set to 200MB -->
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>209715200</param-value>
</init-param>
<init-param>
<param-name>forceparser</param-name>
<param-value>false</param-value>
</init-param>
</filter>