Hello All,
I am facing a problem in my application when it is being deployed on server where we are using tomcat, application runs fine on localhost. I am using struts for developing the application.
In one part of the application I am extending org.apache.struts.actions.DownloadAction class to download a file which is present on the server.
but it throws this exception
exception
javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet .java:627)
javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
root cause
java.lang.NullPointerException
org.apache.struts.actions.DownloadAction.copy(Down loadAction.java:139)
org.apache.struts.actions.DownloadAction.execute(D ownloadAction.java:112)
org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet .java:627)
javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
my action class goes like this...
import java.io.File; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DownloadAction; import org.apache.struts.actions.DownloadAction.ResourceStreamInfo; import org.apache.struts.actions.DownloadAction.StreamInfo; import javax.servlet.http.HttpSession; import forms.UploadFileForm; public class DownloadMagazineAction extends DownloadAction { protected StreamInfo getStreamInfo(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception { String filepath = null; String foldername = null; HttpSession session = request.getSession(true); UploadFileForm uploadform = (UploadFileForm) form; System.out.println("sesssion month and year in download action is " + session.getAttribute("month")+ session.getAttribute("year")); foldername = (String)session.getAttribute("month") + session.getAttribute("year"); System.out.println("folder name from session : " + foldername); String fileName = request.getParameter("filename"); System.out.println("filename : " + fileName); filepath = "Magazine_" + foldername + "/" + fileName; System.out.println("Filepath : " + filepath); File file = new File(filepath); String name = file.getName(); String contentType = "application/octet-stream"; response.setHeader("Content-disposition", "attachment; filename=" + name); response.setHeader("Pragma", "no-cache"); ServletContext application = servlet.getServletContext(); System.out.println("application : " + application); return new ResourceStreamInfo(contentType, application, filepath); } }
I was taking the month and year from the form object but to see if the problem is because of the form I changed the same to session and tried to get the data from session variable. But still it is not working.
I dnt know from where this DownloadAction.copy is generated and why is the application giving error after deployment and not at server
can somebody please help me out with this problem... I am tryig to get rid of this from last so many days but have not got any success
Questions or comments? Feel free to post them here. No login or id required.