[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Uploading files with Jsp and struts

Posted on 2004-11-17
17
Medium Priority
?
252 Views
Last Modified: 2013-11-24

Hey

Am using struts to do upload of files from clients (with jsps) and i'm getting the following error

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
      org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
      org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
      org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
      ie.sentenial.application.actions.UploadAction.execute(Unknown Source)
      org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
      org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


ANyone know what the problem is???

Thakns
0
Comment
Question by:fyness
  • 5
  • 5
  • 4
14 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12603366
WHat is the line of the exception? Can you also post the full stack trace from Tomcat's logs?
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12603376
please also post UploadAction.execute()
0
 

Author Comment

by:fyness
ID: 12603431
tomcat logs was

2004-11-17 12:41:51 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
      at ie.sentenial.application.actions.UploadAction.execute(Unknown Source)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
      at java.lang.Thread.run(Thread.java:534)

2004-11-17 12:41:51 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
      at ie.sentenial.application.actions.UploadAction.execute(Unknown Source)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
      at java.lang.Thread.run(Thread.java:534)

Upload action

 public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response )
        {
             
              
          UploadActionForm f = (UploadActionForm)form ;
          try {
                  InputStream fileInput = f.getFile().getInputStream() ;
                  // do stuff with the input stream to read the file in, then close it
            } catch (FileNotFoundException e) {
                  e.printStackTrace();
            } catch (IOException e) {
                  e.printStackTrace();
            }
        
            if(request.getParameter("action") == null || request.getParameter("action").equalsIgnoreCase(null))
            {
                  return (mapping.findForward("upload"));
            }
            else if(request.getParameter("action").equals("form"))
            {                  
                  return (mapping.findForward("upload"));
            }
            else
            {
                  return (mapping.findForward("upload"));
            }
        }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 12603438
And the line the error was thrown?
0
 

Author Comment

by:fyness
ID: 12603443
i dont know what line threw the error
0
 

Author Comment

by:fyness
ID: 12603447
would prob be


 else if(request.getParameter("action").equals("form"))
          {              
               return (mapping.findForward("upload"));
          }
0
 
LVL 35

Expert Comment

by:girionis
ID: 12603457
Ok we can start by the most obvious. Can you make sure that the file "f" is not null? Put a Systsem.out statement and see if it is null: System.out.println("f: " + f);
0
 
LVL 35

Expert Comment

by:girionis
ID: 12603461
I'd suggest you put a few System.out statements and see what is null. Then we can go on from there.
0
 

Author Comment

by:fyness
ID: 12603509
the file should be empty at the moment becuase nothign has been uploaded yet...i get this error when i try go to the jsp that will allow a client to upload a file f
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12603513
fyness,
did u defined UploadActionForm as the form bean for u action in strutsconfig.xml?
 please post ur action definition in strutsconfig.xml
0
 

Author Comment

by:fyness
ID: 12603626
yep

 <form-bean name="uploadActionForm" type="application.forms.UploadActionForm" />


  <action path="/dataUploadAction"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>
   
    <action path="/upload"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 500 total points
ID: 12603682
nooop u didn't ;-)

u did the first part only
>>  <form-bean name="uploadActionForm" type="application.forms.UploadActionForm" />

secondly those:

>>
  <action path="/dataUploadAction"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>
   
    <action path="/upload"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>

>>
should be:

 <action name="uploadActionForm" path="/dataUploadAction"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>
   
    <action name="uploadActionForm" path="/upload"
            type="ie.sentenial.application.actions.UploadAction"
            scope="request">
    </action>
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12799245
Venabili
I think I answered and deserve the Acceptance for my last comment
0
 
LVL 35

Expert Comment

by:girionis
ID: 12800919
I also think permagdy's last comment is the valid answer.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month19 days, 14 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question