aspose file tools*
The moose likes JSP and the fly likes Upload and Download files just like attachments in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Upload and Download files just like attachments in JSP" Watch "Upload and Download files just like attachments in JSP" New topic
Author

Upload and Download files just like attachments in JSP

Kaushal Pandya
Greenhorn

Joined: Feb 15, 2006
Posts: 9
Hi everyone,
I am using JSP as a front-end view purpose,
From this page I have to push the data to one of the Action Request System form (AR System 6.3). I am using ARS JAVA API.
As per requirement I have to upload one file from user on JSP and have to push it to this back-end form.
I tried JavaZoom�s javazoom.upload class but its giving me a error and I couldn�t fine this class file anywhere. So this code didn�t work finally.
I need a urgent solution friends.
Please respond with some positive solutions.
Thank you,
Kaushal.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

We have a file upload entry in our faq.
See:
http://faq.javaranch.com/search?FileUpload


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
Hai Ben,
i am using common file upload by jakarta to yupload file from client side to server i am having error while doing so....Can anyone solve the problem
Error :
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
ServletFileUpload cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
ServletFileUpload cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
FileItemIterator cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
FileItemStream cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
InputStream cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
StreamUtil cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
ServletFileUpload cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
ServletFileUpload cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
FileItemIterator cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
FileItemStream cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
InputStream cannot be resolved to a type

An error occurred at line: 7 in the jsp file: /ProcessFileUpload.jsp
Generated servlet error:
StreamUtil cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

My HTML:


[BPSouther: Added UBB Code tags]
[ November 28, 2006: Message edited by: Ben Souther ]

jothish
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42945
    
  68
ServletFileUpload is in package org.apache.commons.fileupload.servlet, which is not imported (org.apache.commons.fileupload is imported twice).

The other missing classes are not part of Commons FileUpload API, AFAICT, and need to be imported as well.

The import statement is also missing a comma at "java.util.Iteratorjava.io.*".

My advice would be to handle file uploads in a servlet, not a JSP. It will be much easier to handle the upload logic and error cases, and then dispatch to one or more JSP pages depending on the outcome.
[ November 27, 2006: Message edited by: Ulf Dittmer ]
Kaushal Pandya
Greenhorn

Joined: Feb 15, 2006
Posts: 9
Try with these code;


[BPSouther: Added UBB CODE tags]
[ November 28, 2006: Message edited by: Ben Souther ]
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
Hai error message for the above code:
HTTP Status 404 - d:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\uploaded\new.xml (The system cannot find the path specified)
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
it is working fine ppl
i have created a folder to put the file
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
One more thing pandya
Can i upload zip file using the above code.....
Any ideas and suggestions please provide me.....
Kaushal Pandya
Greenhorn

Joined: Feb 15, 2006
Posts: 9
Hey jothish,
as far as i tested it... it will work for any kind of file.
.doc, .xls, .zip. etc...
if you have any problem do contact me regarding it.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Kaushal Pandya,

Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.
Kaushal Pandya
Greenhorn

Joined: Feb 15, 2006
Posts: 9
Thanks Ben,
will keep this in mind.
thank you once again.
jothish chokkalingam
Ranch Hand

Joined: Jan 02, 2006
Posts: 57
Ppl,
One more thing downloading a csv file from server i am facing a problem...
My pice of code to throw output to browser
Is this the way to do this....?

For the above code i am getting the output stream from browser not the expected one it is throwing with error message stating couldn't read the file
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload and Download files just like attachments in JSP