| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I have created a html page for uploading of file.. <body> <form method="post" enctype="multipart/form-data" action="http:// localhost:8080/LabMgmt1/upload.jsp"> <input type="file" size=20 name="fname"> <input type="Submit" value="Upload"> </form> </body> Now I want to get the uploaded file in upload.jsp and save it in a folder. How can I do it? Plz help ! |
|
#2
| |||
| |||
| On 27-8-2008 12:37, snehapshinde@gmail.com wrote: > I have created a html page for uploading of file.. > <body> > <form method="post" enctype="multipart/form-data" action="http:// > localhost:8080/LabMgmt1/upload.jsp"> > <input type="file" size=20 name="fname"> > <input type="Submit" value="Upload"> </form> > </body> > Now I want to get the uploaded file in upload.jsp and save it in a > folder. > How can I do it? > Plz help ! Probably the easiest is to use the Jakarta Commons Fileupload library (rather than writing it yourself). <http://commons.apache.org/fileupload/> <http://commons.apache.org/fileupload/using.html> -- Regards, Roland |
|
#3
| |||
| |||
| On 27-8-2008 14:10, Roland de Ruiter wrote: > On 27-8-2008 12:37, snehapshinde@gmail.com wrote: >> I have created a html page for uploading of file.. >> <body> >> <form method="post" enctype="multipart/form-data" action="http:// >> localhost:8080/LabMgmt1/upload.jsp"> >> <input type="file" size=20 name="fname"> >> <input type="Submit" value="Upload"> </form> >> </body> >> Now I want to get the uploaded file in upload.jsp and save it in a >> folder. >> How can I do it? >> Plz help ! > Probably the easiest is to use the Jakarta Commons Fileupload library > (rather than writing it yourself). > > <http://commons.apache.org/fileupload/> > <http://commons.apache.org/fileupload/using.html> The Commons Fileupload library also needs Commons IO library (at least at runtime; I don't think it's needed at compile time). <http://commons.apache.org/io/> -- Regards, Roland |
|
#4
| |||
| |||
| snehapshinde@gmail.com wrote: > I have created a html page for uploading of file.. > <body> > <form method="post" enctype="multipart/form-data" action="http:// > localhost:8080/LabMgmt1/upload.jsp"> > <input type="file" size=20 name="fname"> > <input type="Submit" value="Upload"> </form> > </body> > Now I want to get the uploaded file in upload.jsp and save it in a > folder. Jakarta FileUpload or COS. I will recommend Jakarta FileUpload unless you have special requirements. Code snippet that processes multiple files: <%@page import="org.apache.commons.fileupload.*,java.util. *,java.io.*"%> <% DiskFileUpload upload = new DiskFileUpload(); List files = upload.parseRequest(request); for(int i = 0; i < files.size(); i++) { FileItem file = (FileItem)files.get(i); if(file.getSize() > 0) { String filename = "C:\\" + file.getFieldName() + ".upl"; file.write(new File(filename)); } } %> Arne |
|
#5
| |||
| |||
| On Aug 28, 5:55*am, Arne Vajhøj <a...@vajhoej.dk> wrote: > snehapshi...@gmail.com wrote: > > I have created a html page for uploading of file.. > > <body> > > <form method="post" enctype="multipart/form-data" action="http:// > > localhost:8080/LabMgmt1/upload.jsp"> > > *<input type="file" size=20 name="fname"> > > *<input type="Submit" value="Upload"> </form> > > </body> > > Now I want to get the uploaded file in upload.jsp and save it in a > > folder. > > Jakarta FileUpload or COS. > > I will recommend Jakarta FileUpload unless you have > special requirements. > > Code snippet that processes multiple files: > > <%@page import="org.apache.commons.fileupload.*,java.util. *,java.io.*"%> > <% > DiskFileUpload upload = new DiskFileUpload(); > List files = upload.parseRequest(request); > for(int i = 0; i < files.size(); i++) { > * * FileItem file = (FileItem)files.get(i); > * * if(file.getSize() > 0) { > * * * *String filename = "C:\\" + file.getFieldName() + ".upl"; > * * * *file.write(new File(filename)); > * * }} > > %> > > Arne I tried with this piece of code, but it is throwing following exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 2 in the jsp file: /upload.jsp Generated servlet error: DiskFileUpload cannot be resolved or is not a type An error occurred at line: 2 in the jsp file: /upload.jsp Generated servlet error: DiskFileUpload cannot be resolved or is not a type An error occurred at line: 2 in the jsp file: /upload.jsp Generated servlet error: FileItem cannot be resolved or is not a type An error occurred at line: 2 in the jsp file: /upload.jsp Generated servlet error: FileItem cannot be resolved or is not a type I don't understand why is it not able to recognize DiskFileUpload and FileItem, even though org.apache.commons.fileupload.* has been imported! Could you please tell me what would be the probable problem? |
|
#6
| |||
| |||
| snehapshinde@gmail.com wrote: > On Aug 28, 5:55 am, Arne Vajhøj <a...@vajhoej.dk> wrote: >> Code snippet that processes multiple files: >> >> <%@page import="org.apache.commons.fileupload.*,java.util. *,java.io.*"%> >> <% >> DiskFileUpload upload = new DiskFileUpload(); >> List files = upload.parseRequest(request); >> for(int i = 0; i < files.size(); i++) { >> FileItem file = (FileItem)files.get(i); >> if(file.getSize() > 0) { >> String filename = "C:\\" + file.getFieldName() + ".upl"; >> file.write(new File(filename)); >> }} >> >> %> > I tried with this piece of code, but it is throwing following > exception > > org.apache.jasper.JasperException: Unable to compile class for JSP > > An error occurred at line: 2 in the jsp file: /upload.jsp > Generated servlet error: > DiskFileUpload cannot be resolved or is not a type > I don't understand why is it not able to recognize DiskFileUpload and > FileItem, even though org.apache.commons.fileupload.* has been > imported! Could you please tell me what would be the probable > problem? import="org.apache.commons.fileupload.* just imports names - it means that DiskFileUpload can be used as abbreviation for org.apache.commons.fileupload.DiskFileUpload - it does not import any code. The error is with almost certainty that you have not put the Jakarta FileUpload jar files in classpath. They should be in WEB-INF/lib ! Arne |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.