tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur_1805 <sur_1...@yahoo.co.in>
Subject give error in upload a image in tomcat 6 but works well in tomcat 4
Date Fri, 13 Jun 2008 12:39:22 GMT

I am using tomcat 4 and write jsp page to upload a image in server it works
with tomcat 4 but it gives error in  upload image in tomcat 6 with the same
jsp page .It gives some java.lang.IndexOutOfBoundsException
at 
--

org.apache.jasper.JasperException: An exception occurred processing JSP page
/Jsp/BOG/upload_scan.jsp at line 154

151: 
152: 		// creating a new file with the same name and writing the content in
new file
153: 		FileOutputStream fileOut = new FileOutputStream(save_File);
154: 		fileOut.write(dataBytes, startPos, (endPos - startPos));
155: 		fileOut.flush();
156: 		fileOut.close();
157:     


the code snippets is given below 

if ((contentType != null) && (contentType.indexOf("multipart/form-data") >=
0)) {
 		DataInputStream in = new DataInputStream(request.getInputStream());
	
		//we are taking the length of Content type data

		int formDataLength = request.getContentLength();
		byte dataBytes[] = new byte[formDataLength];
		int byteRead = 0;
		int totalBytesRead = 0;

		//this loop converting the uploaded file into byte code
		while (totalBytesRead < formDataLength) {
			byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
			totalBytesRead += byteRead;
			}
    
	  	String file = new String(dataBytes);
		//for saving the file name
		 saveFile = file.substring(file.indexOf("filename=\"") + 10);
		

		saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
		saveFile = saveFile.substring(saveFile.lastIndexOf("\\") +
1,saveFile.indexOf("\""));
        String extension = saveFile.substring(saveFile.lastIndexOf("."));

 int count=0;
String sql = "select count(table_id)  from bog_table where met_key='" +
key+"' and item_id='"+item+"'";

				ResultSet rt=null;
//out.println(sql);
rt = am.fetchRecordSet(sql);
	String table_id="";
	String table_ref="";			
				if(rt.next()){
			
				
				count=rt.getInt(1)+1;
			 
			 table_id="TableId-" + count;
			table_ref= key+"-"+item+"-"+table_id+"-TableRef-" +count;	
			
				}
         saveFile = table_ref + extension;
       save_File ="/data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG/"  +
saveFile;	

        int lastIndex = contentType.lastIndexOf("=");
		String boundary = contentType.substring(lastIndex +
1,contentType.length());
		int pos;
		//extracting the index of file 
		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;

		// creating a new file with the same name and writing the content in new
file
		FileOutputStream fileOut = new FileOutputStream(save_File);
		fileOut.write(dataBytes, startPos, (endPos - startPos));
		fileOut.flush();
		fileOut.close();
    

||||||


please give me the solution

-- 
View this message in context: http://www.nabble.com/give-error-in-upload-a-image-in-tomcat-6-but-works-well-in-tomcat-4-tp17822463p17822463.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message