Results 1 to 12 of 12
Thread: http status 500
- 05-05-2011, 01:52 PM #1
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
http status 500
iam getting this error in processing of my jsp page
http status 500
this is error in my code
org.apache.jasper.JasperException: An exception occurred processing JSP page /insertion.jsp at line 26
23: <% int sid=Integer.parseInt(request.getParameter("stdid") );
24: String sname=request.getParameter("stdname");
25: int avgmark=Integer.parseInt(request.getParameter("avg "));
26: ps.setInt(1,sid);
27: ps.setString(2,sname);
28: ps.setInt(3,avgmark);
29: rs = ps.executeUpdate();
thank u.
- 05-05-2011, 02:26 PM #2
- 05-06-2011, 11:44 AM #3
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
hai petr ,this is my jsp code could u plz tell me where the error occured
<%@page import="java.sql.*;" %>
<%!
Connection con=null;
PreparedStatement ps=null;
int rs=0;
%>
<%! public void jspInit()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin: @localhost:1521:orcl","scott","tiger");
ps=con.prepareStatement("insert into students values(?,?,?)");
}
catch(Exception e)
{
e.printStackTrace();
}
}
%>
<% int sid=Integer.parseInt(request.getParameter("stdid") );
String sname=request.getParameter("stdname");
int avgmark=Integer.parseInt(request.getParameter("avg "));
ps.setInt(1,sid);
ps.setString(2,sname);
ps.setInt(3,avgmark);
rs = ps.executeUpdate();
if(rs!=0)
out.println("Record inserted successfully");
else
out.println("Record insertion failed");
%>
<%! public void jspDestroy()
{
try
{
con.close();
ps.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
%>
- 05-06-2011, 11:48 AM #4
- 05-06-2011, 12:46 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Yep.
I would bet that the creation of the PreparedStatement (or connection) has resulted in an exception, meaning ps is null. So ps.setInt() will be throwing a NullPointerException.
None of this code should be in a JSP.
It should be in its own layer (ie set of classes) and called from a Servlet.
- 05-07-2011, 01:08 PM #6
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
hai petr, thanks for ur reply,
but i can't understand ur statement
is it means the errors occured at the running server or jsp equalent servlet program.
thanks.
- 05-07-2011, 01:22 PM #7
How I guess you use Tomcat as jsp/servlet container. so tomcat compiles jsp page in run time, hence if you have mistake in jsp server will ask about your mistake. For it you need look in log file by server or use follows approach.
In descriptor your app (web.xml) you add follows statements
and add Error.jsp likeJava Code:<error-page> <error-code>404</error-code> <location>/jsp/Error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/jsp/Error.jsp</location> </error-page>
The same way you can have whole stack trace and understand where you made mistake.Java Code:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%> <%@ page import="java.io.PrintWriter" %> <% if(exception instanceof ServletException) if(exception.getCause() != null) exception = exception.getCause(); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Error page</title> </head> <body> <b><%=exception.getMessage()%></b><br> <textarea name="stacktrace" style="height:500px;width:700px;" readonly="readonly"><%exception.printStackTrace(new PrintWriter(out));%></textarea> </body> </html>Skype: petrarsentev
http://TrackStudio.com
- 05-08-2011, 12:45 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Or, simply, don't do processing like this in a JSP page...
- 05-09-2011, 02:09 PM #9
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
hello Petr thanks for ur concern,
i have added ur code to my application,but when i clicked on insert button nothing will be happened in browser window as well as in server.
Thank U.
- 05-09-2011, 02:16 PM #10
I forget you need add follows statement on your page
in begin
Java Code:<%@ page buffer="128kb" errorPage="/jsp/Error.jsp" %>
Skype: petrarsentev
http://TrackStudio.com
- 05-09-2011, 02:31 PM #11
Please go through this link.
db
- 05-09-2011, 02:41 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
HTTP Status 500 -
By aiesha in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-23-2011, 04:16 AM -
http://localhost:8080/helloservice/HelloService?Tester HTTP Status 404 -
By vietnamusa in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 03-13-2011, 12:02 AM -
HTTP Status 500 -
By gardiann in forum Java ServletReplies: 2Last Post: 12-26-2010, 12:49 PM -
http status 500
By swathi dharmaraj in forum Java ServletReplies: 4Last Post: 12-14-2010, 04:46 PM -
HTTP Status 405 - HTTP method GET is not supported by this URL
By javanewbie in forum Java ServletReplies: 7Last Post: 11-11-2009, 08:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks