Results 1 to 12 of 12

Thread: http status 500

  1. #1
    sudha333 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    it mean that you have mistake in your jsp.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    sudha333 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

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

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Can you show log from a server?
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default

    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.

  6. #6
    sudha333 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

    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.

  7. #7
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    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
    Java 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>
    and add Error.jsp like
    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>
    The same way you can have whole stack trace and understand where you made mistake.
    Skype: petrarsentev
    http://TrackStudio.com

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default

    Or, simply, don't do processing like this in a JSP page...

  9. #9
    sudha333 is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default

    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.

  10. #10
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    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

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Quote Originally Posted by sudha333 View Post
    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.
    Please go through this link.

    db

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default

    Anyone got a convenient link on why not to do this stuff in a JSP?

Similar Threads

  1. HTTP Status 500 -
    By aiesha in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-23-2011, 04:16 AM
  2. http://localhost:8080/helloservice/HelloService?Tester HTTP Status 404 -
    By vietnamusa in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-13-2011, 12:02 AM
  3. HTTP Status 500 -
    By gardiann in forum Java Servlet
    Replies: 2
    Last Post: 12-26-2010, 12:49 PM
  4. http status 500
    By swathi dharmaraj in forum Java Servlet
    Replies: 4
    Last Post: 12-14-2010, 04:46 PM
  5. Replies: 7
    Last Post: 11-11-2009, 08:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •