0

Hello everybody,
As i m beginner to Jsp/Servlet..
I want to Upload a image from client side and store it in MySql database then simultaneously display it.

I need it urgently can anybody send me the code.......

Please,.....


Thanks

3
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by jahanruhi3@gmai
0

Thanks....but i hav tried that...and failed..

import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;

I have the above code errors....
I m using tomcat 5.5...can u plz help me in resolving that..

0

Thank you very much....errors are cleaned...
I will try for the code if any problem in future i need ur help..plz..

Thanks a lot

0
<%	
 
	String contentType = request.getContentType();
	System.out.println("Content type is :: " +contentType);
	if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
	DataInputStream in = new DataInputStream(request.getInputStream());
	int formDataLength = request.getContentLength();
	byte dataBytes[] = new byte[formDataLength];
	int byteRead = 0;
	int totalBytesRead = 0;
	while (totalBytesRead < formDataLength) {
	byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
	totalBytesRead += byteRead;
	}
	String file = new String(dataBytes);
	String saveFile = file.substring(file.indexOf("filename=\"") + 10);
	//out.print("FileName:" + saveFile.toString());
	saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
	//out.print("FileName:" + saveFile.toString());
	saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
	int lastIndex = contentType.lastIndexOf("=");
	String boundary = contentType.substring(lastIndex + 1,contentType.length());
	//out.println(boundary);
	int pos;
	pos = file.indexOf("filename=\"");
	pos = file.indexOf("\n", pos) + 1;
	pos = file.indexOf("\n", pos) + 1;
	pos = file.indexOf("\n", pos) + 1;
	int boundaryLocation = file.indexOf(boundary, pos) - 4;
	int startPos = ((file.substring(0, pos)).getBytes()).length;
	int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
	saveFile = "C:\\apache-tomcat-6.0.29\\webapps\\ROOT\\Extrusions\\" + saveFile;
	FileOutputStream fileOut = new FileOutputStream(saveFile);
	fileOut.write(dataBytes, startPos, (endPos - startPos));
	fileOut.flush();
	fileOut.close();
	out.println("File saved as " +saveFile);

	}
	rs.close();
	    stmt.close();
	    con.close();
	%>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

0

Hi Everyone, i am new to webservice,i need to call webservice from client machine,i dont know the steps what to do,pls guide me ,pls send me a sample code to call the methods of webserver from my client machine.waiting for u r replay

regards,
<EMAIL SNIPPED>

Edited by peter_budo: Keep It Organized - Do not ask anyone (member or moderator) for help by email or PM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.