[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Servlets

Posted on 2007-09-30
3
Medium Priority
?
276 Views
Last Modified: 2013-12-02
I'm using tomcat with netbeans and developing some servlets.

I have the current code:

public class client extends HttpServlet {
   
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
       
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Admin Area </title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1> Version 3 Admin</h1></br>");
 
           
       
        dbManage db = new dbManage();
       
       
        String username = request.getParameter("un") ;
       
        String action = request.getParameter("action");
   
        if(action.equals("create")){
        createUser.createTables(username);
        out.println("<p>User account:  has been created.</p>");
       
        } else if (action.equals("delete")) {
       deleteAccount.deleteTables(username);
       out.println("<p>User account has been deleted.</p>");
        } else {
           
        }
       //createUser.createTables(username);
       
       out.println("</body>");
       out.println("</html>");
       out.close();
     
    }


When run, I get the error:


HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

java.lang.NullPointerException
      client.processRequest(client.java:45)
      client.doGet(client.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.




However, if I put out.close() right after:

out.println("<h1>Version 3 Admin</h1></br>");

It works fine..

Any ideas?

0
Comment
Question by:rameenvaswani
3 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 664 total points
ID: 19988794
> client.processRequest(client.java:45)
whats there at line 45?
0
 
LVL 15

Assisted Solution

by:bpmurray
bpmurray earned 664 total points
ID: 19993207
You are referencing a bunch of DB stuff which isn't included in the source. My guess is that one of these calls has failed, and you are using the return value without checking that it's valid, hence the NullPointerException.
0
 
LVL 1

Accepted Solution

by:
sivakumarmsc earned 672 total points
ID: 20039475
You are processing request parmeters with out checking for Null. You should always check the request parameters for Null. This might also be a reason.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question