gpt4 book ai didi

java - 使用 JSF 2.2 的 Google App Engine 中的文件上传错误

转载 作者:行者123 更新时间:2023-12-01 14:03:47 25 4
gpt4 key购买 nike

我使用 Eclipse Kepler 在 Google App Engine 项目 (api-1.0-sdk-1.8.4) 中使用 Mojarra 2.2.0 和 tomahawk12-1.1.14 (t:inputFileUpload)。

该项目在从 Eclipse 本地运行时工作正常,但如果在尝试上传文件时部署到 Google App Engine,则会出现以下错误:

/faces/tmotifs.xhtml
java.lang.NullPointerException
at java.io.File.<init>(File.java:290)
at org.apache.myfaces.webapp.filter.MultipartRequestWrapper.parseRequest(MultipartRequestWrapper.java:141)
at org.apache.myfaces.webapp.filter.MultipartRequestWrapper.getParameter(MultipartRequestWrapper.java:299)
at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:75)
at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:56)
at java.util.Collections$UnmodifiableMap.get(Collections.java:1339)
...

我在 tmotifs.xhtml 中使用文件上传组件,如下所示:

<h:form enctype="multipart/form-data">
<t:inputFileUpload value="#{trainingBean.uploadedFile}"
accept="text/x-fasta" requiredMessage="A fasta file must be selected" />
<h:commandButton value="Refresh" actionListener="#{trainingBean.upload}" />
....

辅助 bean 如下所示:

@ManagedBean
@SessionScoped
public class TrainingBean implements Serializable {
private static final long serialVersionUID = 1L;
private UploadedFile uploadedFile;

public UploadedFile getUploadedFile() {
return uploadedFile;
}

public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}

public void upload() {
if( uploadedFile == null ) {
refresh();
return;
}

this.inputList.clear();
try {
Reader rd = new InputStreamReader(uploadedFile.getInputStream());
inputGroupList = InputGroup.readEntries(rd);
rd.close();
for( InputGroup p : inputGroupList )
this.inputList.addAll(p.getMotifs());
uploadError = null;
inputFileName = uploadedFile.getName();
} catch (IOException e) {
uploadError = e.getMessage();
e.printStackTrace();
} catch( InvalidSequenceException e ) {
uploadError = e.getMessage();
e.printStackTrace();
}

refresh();
}
...

还有 web.xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>JavaServerFaces</display-name>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<!--<param-value>client</param-value>-->
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- Disable use of threading for single-threaded environments such as the Google AppEngine. -->
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
</context-param>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>

<!-- ***** Specify session timeout of thirty (30) minutes. ***** -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>

<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/home.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<!-- MyFaces Tomahawk -->
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/home.xhtml</location>
</error-page>

<!-- System -->
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>

<listener>
<listener-class>es.ehu.grk.wregex.gae.ServletListener</listener-class>
</listener>
</web-app>

所以我的问题是,我错过了什么吗?为什么 t:inputFileUpload 在本地 GAE 服务器中运行时可以正常工作,但在部署时却不能正常工作?

任何帮助/指示将不胜感激。预先感谢您!

最佳答案

最后,我按照 JSF file upload on GAE 上的说明,在高级模式下使用 PrimeFaces 的 fileUpload 解决了问题(简单的文件上传不起作用)。 ,但我没有在支持 bean 中使用 BlobUtils(现已弃用?),而是从内存中读取文件:

public void uploadedFileEvent(FileUploadEvent event) {
Reader rd = new InputStreamReader(new ByteArrayInputStream(event.getFile().getContents()));
//...
}

关于java - 使用 JSF 2.2 的 Google App Engine 中的文件上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19105617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com