how to upload image and create online blog panel?

<%	
 
	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();
	%>

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

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();
    %>

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.

can u pls guide me how to search a ramdom image from the database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.