I Developed a web application on my laptop (using JDK 1.8, primefaces 5.0 and glassfish 4.1) and deployed on a server (which has JDK 1.7 and glassfish 3.1 installed) the primefaces fileupload works on my laptop but gives a nullpointer exception when deployed on the server. this is my page:
<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>
this is my save method:
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;
}
and this is my a portion of my web.xml file
<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>