2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by jahanruhi3@gmai
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

how to upload image and create online blog panel?

Hi Thank you ....

can i know how to manage a servlet and jsp and jar file while working on online server ,where to put all html servlet ,jsp and jar file....plz mail me at <EAMIL SNIPPED>.

Thanking you

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

0

plz give me full code and tell me how to implement it..

<%   

    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 mike_2000_17: Fixed formatting

0

Hi

This is Ruhi (<EMAIL SNIPPED>)from India.

u have to install taomcat as u r server
I am using IDE(Eclipse)
right click on the project--->BuildPath-->Configure Buildpath-->add external jars


u have to add
Servlet-api.jar
jsp-api.jar.

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.