• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

500 Servlet Exception  RSS feed

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai, i written code for the guestbook, but i get 500 Servlet Exception, could any one help me where i get the error. In myprogram i have written the correct mycode .
thanx
prabhakar.

MyException:
~~~~~~~~~~~
500 Servlet Exception
java.lang.NullPointerException
at abc.MyGuestBook.doPost (MyGuestBook.java:47) (pc 247)
at javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
(HttpServlet.java:165) (pc 263)
at javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,javax.servlet.ServletResponse)
(HttpServlet.java:103) (pc 15)
at com.caucho.server.http.FilterChainServlet.doFilter (FilterChainServlet.java:82)
(pc 6)
at com.caucho.server.http.Invocation.service (Invocation.java:280)
(pc 288)
at com.caucho.server.http.RunnerRequest.handleRequest (RunnerRequest.java:346)
(pc 410)
at com.caucho.server.http.RunnerRequest.handleConnection (RunnerRequest.java:269)
(pc 63)
at com.caucho.server.TcpConnection.run (TcpConnection.java:140)
(pc 78)
at java.lang.Thread.run (Thread.java:504) (pc 11)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
code :
~~~~~
package abc;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class MyGuestBook extends HttpServlet {
Connection con;
public void init( ServletConfig config ) throws ServletException {
super.init(config);
try{
Class.forName("org.hsql.jdbcDriver");
con=DriverManager.getConnection("jdbc:HypersonicSQL:/members/mycode/cgiserver/DB","name","passwd");
}
catch(Exception e)
{
e.printStackTrace();
}
}// End of init

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException,throwable {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
System.out.println("Before the parameters");
String s1=req.getParameter("slno");
String s2=req.getParameter("name");
String s3=req.getParameter("mail");
String s4=req.getParameter("url1");
String s5=req.getParameter("city");
String s6=req.getParameter("state");
String s7=req.getParameter("country");
String s8=req.getParameter("message");
//String s1=req.getParameter("slno");
out.println("after the [arameters");
int abc=Integer.parseInt(s1);
String query="INSERT INTO guestbook(id,name,email,url1,city,state,country,comments) values("+abc+",'"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"')";
out.println("<html><head><title> Guest Book !!</title></head><body>");
try {
out.println("Query created:\t"+query);
Statement stmt=con.createStatement();
out.println("Statement was successfull");
stmt.executeUpdate(query);
out.println("After Update");
stmt.close();
out.println("<br><b>Update Successfull</b>");
}
catch(SQLException ex) {
ex.printStackTrace();
out.println("Update Not Successfull<br>");
//String str=ex.printStackTrace();
out.println("<b><p>Exception :</b><br>"+ex+"<p>");
}
out.println("</body></html>");
out.close();
}// End of doPost
}// End of class
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The evidence is right in front of you:
500 Servlet Exception
java.lang.NullPointerException
at abc.MyGuestBook.doPost (MyGuestBook.java:47) (pc 247)
---------------------------------------------^
whatever you are doing on line 47, there is a null pointer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!