what i require is suppose i press submit button. the file selected using browse should be uploaded in some location.
can anybody give hints like what i can do??
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
0
Since you know about the proper HTML element already, I suppose this question is about the server side? If the receiving end is a Java servlet, then you can use a library like Apache Commons FileUpload to deal with it; it's quite easy to use.
this is the error i am getting.
any idea why is it so?
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 9 in the generated java file
Only a type can be imported. org.apache.commons.fileupload.servlet.ServletFileUpload resolves to a package
An error occurred at line: 10 in the generated java file
Only a type can be imported. org.apache.commons.fileupload.disk.DiskFileItemFactory resolves to a package
An error occurred at line: 34 in the jsp file: /upload_file_multipale.jsp
String literal is not properly closed by a double-quote
31: item.write(savedFile);
32:
33:
34: out.println("<tr><td><b>Your file has been saved
35: at the loaction:</b></td></tr><tr><td><b>"+config.getServletContext().getRealPath
36: ("/")+"uploadedFiles"+"\\"+itemName+"</td></tr>");
37: } catch (Exception e) {
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
i think this is a issue realted to adding some external jar to be added can anyone tell me which jar has to be added?
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
am using tomacat server does anybody knows which are the external jars that has to be added and which one's to keep in lib folder?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
0
Is your first name really "january"? If not, we have a policy on screen names here at JavaRanch. Basically, it must consist of a real-sounding first name and last name, and not be obviously fictitious. If yours does not conform with it, please take a moment to change it, which you can do using the "My Profile" link at the top of the page.
Obviously, you need to have the FileUpload jar file in the WEB-INF/lib folder of your web app. It's usually called something like "commons-fileupload-1.2.1.jar".
It's also bad design to keep file I/O code in your JSP pages. It makes proper error handling (amongst other things) hard to do. You should move that code to a servlet instead.
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
yes my first name is january.
After adding the jar file to the LIB folder also am not able to get the files uploaded to the given path
The Jsp is executing and just showing
your files uploaded..
but acutal uploading is not happening.
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Do not write Java code in JSP files. Scriptlets indicate a bad design and are receipt for disaster. They are highly discouraged.
Write Java code in Java classes. Servlets are highly suitable for your requirement.
That greatly depends upon which upload package you are using. Read its documentation.
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Am using apache uploading package
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
0
If you have code inside of an if-block not executing, then the first guess would be that the if condition evaluates to false. Do you understand what "isFormField" checks?
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
yes. its basically a text field. but in my case isFormField always returns false and Document Name textField is never read.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
0
The HTML of the documentname field is malformed; that's probably what causes the trouble.
A tool like the Firefox extension LiveHttpheaders can help troubleshoot problems like this one by showing what exactly gets transmitted in the HTTP request and the response.
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Thnkx for the reply..
so should i change my front end style.. i mean HTML tags.. because as per my requirement more styling is not required..!!
Who said anything about style? Your HTML is invalid.
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Hi All
when i saved the above malfunctioned file as jsp and clicked submit i was not able to read the text field value
but when the same thing i saved as HTML and submitted values i was able to read the text value entered.
can anyone tell me why this happened??
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
this is my final 2 files
FIRST FILE
SECOND FILE
now my question when i saved the FIRST file here as jsp and clicked submit i was not able to get Document name from the second file. but when i saved the first file as HTML and clicked submit i got the DOCUMENT name from the second file.
So can any anybody expalin why the difference?
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Again, JSP is a view technology. You should not write raw Java code in a JSP file. Java code belongs in Java classes. In your specific case, a Servlet is perfectly suitable for this.
Apart from your problem, the HTML <center> tag is deprecated since HTML 4.01 in 1998. You shouldn't be using it as it is subject to removal from the future HTML specifications. The same applies to the HTML <font> tag, if you wasn't aware about it. Both are pure styling tags and thus totally not semantic. You should be using CSS for styling.
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Thanks for your reply.
But i was asked to design it using jsp only by my project manager so did it.
he does not like servlets i think. :roll:
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
/**** can i retrieve these values without using Iterator?? *********/ i want the two files attached in separate variables
J radolf
Ranch Hand
Joined: Jan 08, 2009
Posts: 121
posted
0
Like in LINE30 the variable filename is in loop and i have 2 files which are coming from a client
so i want to keep these files stored in 2 different variables,rather then in a loop so what can i do??