Uploading files with Jsp and struts


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
fynessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
WHat is the line of the exception? Can you also post the full stack trace from Tomcat's logs?
0
petmagdyCommented:
please also post UploadAction.execute()
0
fynessAuthor Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

girionisCommented:
And the line the error was thrown?
0
fynessAuthor Commented:
i dont know what line threw the error
0
fynessAuthor Commented:
would prob be


 else if(request.getParameter("action").equals("form"))
          {              
               return (mapping.findForward("upload"));
          }
0
girionisCommented:
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
girionisCommented:
I'd suggest you put a few System.out statements and see what is null. Then we can go on from there.
0
fynessAuthor Commented:
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
petmagdyCommented:
fyness,
did u defined UploadActionForm as the form bean for u action in strutsconfig.xml?
 please post ur action definition in strutsconfig.xml
0
fynessAuthor Commented:
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
petmagdyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petmagdyCommented:
Venabili
I think I answered and deserve the Acceptance for my last comment
0
girionisCommented:
I also think permagdy's last comment is the valid answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.