我在我的笔记本电脑上开发了一个Web应用程序(使用JDK 1.8,primefaces 5.0和glassfish 4.1)并部署在一台服务器上(安装了JDK 1.7和glassfish 3.1),primefaces fileupload在我的笔记本电脑上工作,但是当我的笔记本电脑上有一个nullpointer异常时部署在服务器上。这是我的页面:
<p:fileUpload update="pimage" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
value="#{newUserBean.file}" required="true"requiredMessage="Select a picture to upload" mode="simple"/>
<h:commandButton style="width: 150px;height: 40px" value="Submit" actionListener="#{newUserBean.save()}">
<f:ajax execute="@all" render="@form"/>
</h:commandButton>
这是我的保存方法:
public void save() {
String url = null;
try {
//String fullname = getSurname() + " "+ getOtherNames();
Map<String, String> map = new NewUserEntity().createUser(1, getUserName(), getSurname(), getOtherNames(), getJob(), getUserGroup(), getPassword(), getEmail(),
Integer.parseInt(getStaffID()), getDateOfBirth(), getAddress(), getPhoneNo(),
getDepartment(), getAcademicQualification(), getGrade(), getProfQuailification(), getCourse(), file.getInputstream(), getSex(), Integer.parseInt(getExtension()));
if (map.get("responseMessage").equalsIgnoreCase("User Added Successfully")) {
url = "addUser.xhtml?faces-redirect=true";
} else {
url = "";
}
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "", map.get("responseMessage"));
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Error", e.toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
//return url;
}
这是我的web.xml文件的一部分
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<error-page>
<exception-type>
javax.faces.application.ViewExpiredException
</exception-type>
<location>/Web Pages/Login.xhtml</location>
</error-page>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>c:/tmp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>