Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2008, 02:22 PM
Member
 
Join Date: Aug 2008
Posts: 2
jeniramires is on a distinguished road
File Upload Servlet problem
Hi everyone,
i have problem with servlet for upload files,every help will be much appreciated.
I am using the Apache API for uploading files.My original servlet is longer than what i will paste here,but i think that if i understand the problem of the short servlet here, i will fix it for my main servlet.The short servlet is this:

import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;

public class TestUploadFiles extends HttpServlet {
public void doGet(javax.servlet.http.HttpServletRequest aRequest , HttpServletResponse aResponse)
throws ServletException , IOException
{
HttpSession session1 = aRequest.getSession();

// boolean isMultipart = ServletFileUpload.isMultipartContent( new ServletRequestContext(aRequest) );
boolean isMultipart = ServletFileUpload.isMultipartContent( aRequest );
}

public void doPost(HttpServletRequest aRequest , HttpServletResponse aResponse )
throws ServletException , IOException
{
doGet(aRequest,aResponse);

}
}

The html form that i am using is this:
<html>
<head>
<title> Upload File Form </title>
</head>
<body>
aaa
<form method=post enctype="multipart/form-data" action="TestUploadFiles">
File to upload: <input type=file name="upfile"><br>
<input type=submit value="Submit">
</form>
</body>
</html>

When i am starting the form on Tomcat , the form appears on the screen, then i push the Browse button and choose a file from the harddisk, then i press the Submit button and i get exception:


javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
org.apache.commons.fileupload.servlet.ServletFileU pload.isMultipartContent(ServletFileUpload.java:68 )
TestUploadFiles.doGet(TestUploadFiles.java:20)
TestUploadFiles.doPost(TestUploadFiles.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

Then i decided to change the row boolean isMultipart = ServletFileUpload.isMultipartContent( aRequest ); with a
boolean isMultipart = ServletFileUpload.isMultipartContent( new ServletRequestContext(aRequest) );

The result when it is executed from the html from (when i choose file from the harddisk and press submit) is exception again, this time it is:
javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
TestUploadFiles.doGet(TestUploadFiles.java:20)
TestUploadFiles.doPost(TestUploadFiles.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

For me it is quite strange, i have been dealing with this problem for 2 days and can't figure the problem.
I have tried to check for the first case if aRequest is null, well - it is not, i have check for the servlet-api.jar - it is in my classpath, it is in the lib directory of tomcat, i have added it and to the lib folder of the webapplication of the file upload servlet that i am writing, i have opened servlet-api.jar and inside everything looks ok, there is HttpServletRequest.Then i checked for commons-fileupload-1.2.1.jar and commons-io-1.4.jar that i downloaded from apache file upload api site - these jars are also in my classpath, they are in the lib directory of Tomcat, finally i added them to the lib folder of the web application - nothing changed. The web.xml file in WEB-INF is in my opinion ok,similar to this in every other web application that i have done.The Tomcat version that i am using is 6.0.18, the file upload api from apache site are the last versions.Btw HttpServletRequest is found in a web application where i don use apache file upload api, i mean i can take parameters from forms,etc, it's ok in my opinion. Please give your opinions,no matter what they are.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-18-2008, 02:36 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
simpler than it looks
Quote:
Originally Posted by jeniramires View Post
...For me it is quite strange, i have been dealing with this problem for 2 days and can't figure the problem......
I wrestled with this for long time too , simple is that there is some sort of remarkably simple approach which revolves around just climibing back along the inheritace tree for servlet - there is some file object back there by which you can just read whatever they ship minus all the folks who tell you it cannot be done. Swamped right now with writing files server-side, will try to check back.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-18-2008, 11:34 AM
Member
 
Join Date: Aug 2008
Posts: 2
jeniramires is on a distinguished road
Hi,thanks for the help,i probably would try to follow the approach you proposed, but it happened that little before i read it i think i solved the problem(btw it really was simpler than it looks).After a couple of unsuccessful tries to understand the what caused these exceptions, i downloaded others API for uploading files, this time from Oreilly.When i wrote one simple file upload application with them, on the first it worked ok.When then i tried it again, it (surprisingly ) stopped to work, with exception like this :java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest . Then again and again it was causing the same exception, when i started it with Mozilla,IE and Opera.It made me think that the problem is not in the API,but in tomcat, then from the tool Monitor Tomcat in the tab JAVA there is a field to choose the the java virtual machine, and it was jre1.5.0_10\bin\client\jvm.dll
so i decided to try with jre6\bin\client\jvm.dll and this seems solved the problem (i hope for this), because after starting round 10 times the simple file upload application, it works excellent.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-18-2008, 09:34 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
okay
Okay, I came here because I found this:

JUpload - File Upload Applet

I am trying to figure out how to write server-only files. If you can be of any help - post in [SOLVED] writing to WEB-INF while on server. which I marked as solved but that was just because I had to many things open. Yesterday I managed to get throwaway AES grade unique request identifiers and today I have come back around to that post. First attempt at running the code proposed in the last post there has showing up in the filename and regex.find("%20").replace(" ") failed , I am trying to employ work from Brian D. Carlstrom and my hopes are back up. I think the apporach that will work is simplifiy to File f = new File("."); but I need any assistance or remarks you can provide as I have a google adwords ready to go from beginner to standard waiting on one sole remaining barrier: Saving the text from a <form><textarea><submit> to a a hardcode file as I understand files and do it on the server so that I have an avenue of retireving what the user actually typed instead of getting some fancy tools' scripting popup asking my if I am satisifed with the screwing I got.

Really inane, with promotional claims ranging as high as eight million dollars a second going on the internet it is needful that I have a code avenue I understand for records of what was sent to Pay Pal and what they sent me back along with what the customer actually typed at the keyboard.

pm me if you want to trade emails or something.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to upload a file? tommy JavaServer Pages (JSP) and JSTL 4 06-30-2008 04:50 PM
file upload sundarjothi JavaServer Pages (JSP) and JSTL 1 06-27-2008 01:52 PM
file upload in java muralikrishna New To Java 6 06-25-2008 10:24 AM
File Upload ShoeNinja JavaServer Pages (JSP) and JSTL 0 11-10-2007 12:09 AM
how to upload a file using servlet simon Java Servlet 1 08-05-2007 05:50 AM


All times are GMT +3. The time now is 09:31 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org