Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes 500 Servlet Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "500 Servlet Exception" Watch "500 Servlet Exception" New topic
Author

500 Servlet Exception

varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 500 Servlet Exception
 
Similar Threads
The server encountered an internal error () that prevented it from fulfilling this request
String code
update problem in oracle
Error while sending Html Mail
Uploading jpeg images to webserver