Forums Register Login

HTTP Status 500

+Pie Number of slices to send: Send
Hello guys,

Really need your helps, regarding ERROR 500.

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception


org.apache.jasper.JasperException: java.lang.StringIndexOutOfBoundsException: String index out of range: -19604

root cause


java.lang.StringIndexOutOfBoundsException: String index out of range: -19604

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.
GlassFish Server Open Source Edition 3.0.1
Untitled.jpg
[Thumbnail for Untitled.jpg]
+Pie Number of slices to send: Send
Ah that doesn't help much. What does the log say? Is there a stack trace? What was the page or code doing?
+Pie Number of slices to send: Send
i try to uploading data from excel into MySql using jsp, then when i run the coding, the page for Uploading going well, but when i try click button submit to MySql, that error appear, HTTP 500.. bellow is the sample code that i have run.


1)Page.jsp

<%@ page language="java" %>
<HTml>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>

<BODY> <FORM ENCTYPE="multipart/form-data" ACTION=
"upload_page.jsp" METHOD=POST>
<br><br><br>
<center><table border="2" >
<tr><center><td colspan="2"><p align=
"center"><B>UPLOAD THE FILE</B><center></td></tr>
<tr><td><b>Choose the file To Upload:</b>
</td>
<td><INPUT NAME="file" TYPE="file"></td></tr>
<tr><td colspan="2">
<p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>


2)Upload_page.jsp

<%@ page import="java.io.*,java.sql.*" %>
<html>
<%
String contentType = request.getContentType();
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);
System.out.println("saveFile=" + saveFile);
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
System.out.println("saveFile" + saveFile);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%>
<b>File <% out.println(saveFile); %> has been uploaded and inserted into Database.</b>
<%Connection con=null;
Statement pst=null;
String line = null;
String value=null;
try{
StringBuilder contents = new StringBuilder();
BufferedReader input = new BufferedReader(new FileReader(saveFile));
while (( line = input.readLine()) != null){
contents.append(line);
}
value = contents.toString();
System.out.println("Value:"+value);
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://192.168.10.59/application?user=root&password=root");
pst=con.createStatement();
int val = pst.executeUpdate("insert into file(file_data) values('"+value+"')");
}
catch(Exception e)
{}
}
%>
</html>



+Pie Number of slices to send: Send
First you should not have java code in your JSP. Use a servlet instead.

For your error? I reckon it's in those substring lines, unable to get the correct positions. Do check the server logs for those println(). If they are there you passed that point.

Also there is no output or logging for your exceptions (it's a empty catch block!!).

Oh it's better to use the File.separator instead of "/" or "\" in your file path.
+Pie Number of slices to send: Send
Do something in your exception handling block, atleast a system out would help. Your's seem to be rather empty!

Have a look here (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) for the reason behind a 500 Internal server error.
+Pie Number of slices to send: Send
And make sure you use the code formatter next time when you attach source code to your post!
Hey! Wanna see my flashlight? It looks like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2418 times.
Similar Threads
JDBC error
CastException: java.lang.String can not be cast to class
Jsp connect
How do I research this error?
error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:55:12.