• Post Reply Bookmark Topic Watch Topic
  • New Topic

File upload issues

 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi to all I'm new here and I'm writing because I'm really getting some problems in this code and I don't know how to "translate" those error messages.
This portion of code is supposed to copy a file selected with a input type="file" object into a server (a sub folder of my site in the webapps/mysite/ of the tomcat directory)
PS: I'm quite new to this, and I'm using tomcat 6.0.20 with The Commons FileUpload package.




getting the following errors during the execution:


org.apache.jasper.JasperException: An exception occurred processing JSP page /reg/reg_art_final.jsp at line 109

106:
107:
108:
109: boolean isMultipart = ServletFileUpload.isMultipartContent(request);
110:
111:
112: DiskFileItemFactory factory = new DiskFileItemFactory();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.reg.reg_005fart_005ffinal_jsp._jspService(reg_005fart_005ffinal_jsp.java:230)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
org.apache.jsp.reg.reg_005fart_005ffinal_jsp._jspService(reg_005fart_005ffinal_jsp.java:173)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)





thanks in advance for your precious answers.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing this in a JSP or a servlet?
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP.
I don't want anything to do with servlets.
I just call an action=page.jsp?par1=ecc... in a form in the same page.



(Edited to make the post not be three times as wide as my screen - PC)



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mull Sheriff wrote:I don't want anything to do with servlets.

Why? Using JSP for anything other than views is a really, really poor practice.
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application just has to do this:

1) Query and update a database (not shown in the code)
2) Uploading files on a server.

Nothing more, so I decided to not use servlets due to complication of the usage (deploying....) and
I was told by other more instructed people (more than me) that they decrease performances.

The first part works perfectly.

Is there a way to make the second part working without using servlets?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was told by other more instructed people (more than me) that they decrease performances.

Look upon all they say with suspicion from here on out.

That's ***terrible*** advice.
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look upon all they say with suspicion from here on out.


Ok.

Now, about the question: is there a way to do that without servlets?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure; a JSP is just a servlet.
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure; a JSP is just a servlet.


let me guess. British humor?

By the way, I'm asking that because before starting to learn how a servlet works, I just want to understand why that code does not work. I do value your advice but I'm trying to not to put so much stuff on the fire since is my first web application.

May I have some serious answer now?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are compiled to servlets--nothing overly amusing here.

Are you pre-compiling the JSP?
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are compiled to servlets--nothing overly amusing here.

Are you pre-compiling the JSP?


I don't know. I just select the webapp from the tomcat menu and navigate from the web pages I have written.
I guess it's tomcat that handles the compiling.
Like I said, all other .jsp pages are compiled with no errors and they work fine: I have problems just with this one.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So to summarize what people have said so far:

A JSP is compiled into a servlet. So you have the choice of putting your code into a servlet, or using a JSP, in which case you end up with a servlet with exactly the same code plus a bunch of JSP scaffolding. Anybody who says using the plain old servlet would "decrease performance" is... no, the forum rule is "Be Nice" so I can't say it.

So just put that code into a servlet and be done with it. No doubt something in your JSP code is confusing the JSP compiler but there's really no point in finding out why because there is really no point in using a JSP in the first place.
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP is compiled into a servlet. So you have the choice of putting your code into a servlet, or using a JSP, in which case you end up with a servlet with exactly the same code plus a bunch of JSP scaffolding. Anybody who says using the plain old servlet would "decrease performance" is... no, the forum rule is "Be Nice" so I can't say it.


Thanks for the explanation: I didn't know.

Now I have another question.
According to the fact that "put that thing into a servlet" it's a very common answer here and
Since you said that there is no point in writing JSP pages, why does this section of the forum exist?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mull Sheriff wrote:Since you said that there is no point in writing JSP pages, why does this section of the forum exist?


I'm sorry, I didn't mean to say there is no point in writing JSPs. The point in writing JSPs is to generate HTML and that's what you should use them for. Since uploading a file doesn't generate any HTML, using a JSP to do it just complicates things unnecessarily.

So put your file-uploading code into a servlet. When the file uploading is done, forward to a JSP which generates the HTML containing the response to the client.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mull Sheriff wrote: Since you said that there is no point in writing JSP pages, why does this section of the forum exist?

No one said that. And continuing with your "attitude" is likely to alienate the very people who can help you most. I suggest a change in strategy.

What the very experienced and senior developers who post have said repeatedly is that using JSP for things for which it is not suited should be avoided. No one said to avoid JSPs -- they're an essential part of any web ap[plication for create the views of the web app.

Using them for processing -- not so much. You can tell when you are going astray as soon as you start putting Java code into a JSP. Big no-no.

And yes, those that told you to avoid servlets -- avoid them. They're telling you nonsense.
 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I didn't mean to say there is no point in writing JSPs. The point in writing JSPs is to generate HTML and that's what you should use them for. Since uploading a file doesn't generate any HTML, using a JSP to do it just complicates things unnecessarily.

So put your file-uploading code into a servlet. When the file uploading is done, forward to a JSP which generates the HTML containing the response to the client.


Thanks again for the answers, I'm going to check out how to build the servlet tomorrow.

No one said that.


My fault. I misunderstood, but thanks to the explanation of Paul Clapham now I get it.

And continuing with your "attitude" is likely to alienate the very people who can help you most. I suggest a change in strategy.


I'm just asking question and I don't want to piss off anyone, but here only Paul Clapham gave me serious answers, other users gave me incomplete answers that did not answered the question of the topic.

Since you said that there is no point in writing JSP pages, why does this section of the forum exist?


This was just a question from a newbie (as I said I am in my first post), I didn't mean to criticize this forum or the users in it.

And yes, those that told you to avoid servlets -- avoid them. They're telling you nonsense.


I know. You are not the only one who told me in this topic.






 
Mull Sheriff
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry: double post


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!