View Full Version : [HELP] How to create image & file upload in jsp?

16 Dec 2010, 12:24 AM
Hi everyone, pls help me to create image & file upload in jsp...

and what data type to save image & file uploaded in PostgreSQL database?

Hopely u all can help me! Thanks b4... :)

16 Dec 2010, 6:16 AM
Plzzz... fix my code below...

My JSP Code :

xtype: 'fileuploadfield',
id: 'file',
emptyText: 'Select an image',
fieldLabel: 'Foto',
name: 'photo-path',
disabled: true
My getting value code in my jsp :

n' in java file. how to get the value for file uploaded? where i placed stored folder?? how i set it? or u have more simply than my code? pls share to me...

thanks for see my problem... n' more thanks if u can help me to fix my problem...

16 Dec 2010, 6:57 AM
On the client, you cannot get the value of a file input.

You can get the content of a file if you use the HTML5 File API.

On the server side, this is a JEE question. There are classes available to process file uploads. They are not normal parameters.


16 Dec 2010, 7:02 AM
I would suggest to take the JS code of one of the examples in the link below:

replace the url in the file-upload.js

url: 'file-upload.php',with your jsp page
and add something like the following to your upload.jsp file:

Actually this is Java Code:

List fileItemsList = servletFileUpload.parseRequest(request);
Iterator it = fileItemsList.iterator();
while (it.hasNext()) {
FileItem fileItemTemp = (FileItem) it.next();
File file = File.createTempFile("upload_", fileItemTemp.getName().substring(fileItemTemp.getName().lastIndexOf('.'), fileItemTemp.getName().length()), finDir);

out.println("{success:true, file:'" + file.getName() + "'}");
After adding some imports, the thing should work!