:) Apologies
package employee; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.ServletActionContext; import javax.servlet.ServletContext; import java.io.File; /** * Created with IntelliJ IDEA. * User: love4059 * Date: 13/03/13 * Time: 8:10 PM * To change this template use File | Settings | File Templates. */ public class SingleFileUploadAction extends ActionSupport { private String description; private File attachment; private String attachmentContentType; private String attachmentFileName; private int complete = 0; public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getAttachmentContentType() { return attachmentContentType; } public void setAttachmentContentType(String attachmentContentType) { this.attachmentContentType = attachmentContentType; } public File getAttachment() { return attachment; } public void setAttachment(File attachment) { this.attachment = attachment; } public String getAttachmentFileName() { return attachmentFileName; } public void setAttachmentFileName(String attachmentFileName) { this.attachmentFileName = attachmentFileName; } public String upload(){ System.out.println(description); System.out.println(attachmentContentType); System.out.println(attachmentFileName); ServletContext servletContext = ServletActionContext.getServletContext(); (NULL POINTER Exception at this LINE) if (attachment != null) { // attachment will be null if there's an error, // such as if the uploaded file is too large String dataDir = servletContext.getRealPath("/WEB-INF"); System.out.println(dataDir); File savedFile = new File(dataDir, attachmentFileName); attachment.renameTo(savedFile); } return "success"; } public int getComplete() { complete += 10; return complete; } } 2013/3/16 Martin Gainty <mgai...@hotmail.com> > Not much anyone can do here if we cant see the code for > employee.SingleFileUploadAction.java > > Martin > ______________________________________________ > Verzicht und Vertraulichkeitanmerkung > Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene > Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte > Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht > dient lediglich dem Austausch von Informationen und entfaltet keine > rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von > E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. > > > > Date: Sat, 16 Mar 2013 10:21:08 +1100 > > Subject: Null Pointer Exception when i use execand Wait with file upload > > From: stalin.pran...@gmail.com > > To: user@struts.apache.org > > > > Hello I am trying to use execandWait interceptor with fileUpload > > interceptor as below. i tried completestack in place of default and i get > > Null pointer exception. > > > > > > <action name="File_singleUpload" class="employee.SingleFileUploadAction" > > method="upload"> > > <interceptor-ref name="fileUpload"> > > <param name="maximumSize">1000000000</param> > > <param name="allowedTypes"> > > image/gif,image/jpeg,image/png > > </param> > > </interceptor-ref> > > <interceptor-ref name="defaultStack"/> > > <interceptor-ref name="execAndWait"> > > <param name="delay">1500</param> > > </interceptor-ref> > > <result name="wait">/jsp/wait.jsp</result> > > <result name="success">/jsp/SingleUpload.jsp</result> > > </action> > > > > > > java.lang.NullPointerException > > > org.apache.struts2.ServletActionContext.getServletContext(ServletActionContext.java:139) > > > employee.SingleFileUploadAction.upload(SingleFileUploadAction.java:58) > > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > > java.lang.reflect.Method.invoke(Method.java:597) > > > com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:446) > > > com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:285) > > > org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57) > > java.lang.Thread.run(Thread.java:680) > > > > > > > > Please advise what i can do. > > > > > > -- > > Warm Regards > > Pranava S Balugari > > > > "Keep Looking Don't Settle" > > -- Warm Regards Pranava S Balugari "Keep Looking Don't Settle"