?
Solved

How to run servlet

Posted on 2005-04-18
12
Medium Priority
?
224 Views
Last Modified: 2010-04-01
I'm trying to run a servlet on the server TOmcat 3.2.3

/*
 * TestServlet.java
 *
 * Created on April 17, 2005, 1:49 AM
 */

package testPack;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author zloy
 * @version
 */
public class TestServlet extends HttpServlet {
   
    /** Initializes the servlet.
     */
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
       
    }
   
    /** Destroys the servlet.
     */
    public void destroy() {
       
    }
   
    /** 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>Servlet</title>");
        out.println("</head>");
        out.println("<body>");
         out.println("Servlet is working");
        out.println("</body>");
        out.println("</html>");
   
        out.close();
    }
   
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
   
}

This is what I see on my screen

Error: 500
Location: /TestAccess/servlet/TestServlet
Internal Servlet Error:

java.lang.NullPointerException
      at java.lang.ClassLoader.resolveClass0(Native Method)
      at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
      at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:430)
      at org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
      at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
      at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
      at org.apache.tomcat.core.Handler.service(Handler.java:254)
      at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
      at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)

Points will be awarded to a person how will tell me how to make this servlet run.

Thank you
0
Comment
Question by:zloy_ochen
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 13811943
Hi,

There is nothing wrong on the servlet. it runs fine with me. Can you send me your web.xml file for the servlet configuration?

Regards
Dave
0
 
LVL 1

Author Comment

by:zloy_ochen
ID: 13811987
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>testPack.TestServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>
            30
        </session-timeout>
  </session-config>
  <welcome-file-list>
    <welcome-file>
            index.jsp
        </welcome-file>
    <welcome-file>
            index.html
        </welcome-file>
    <welcome-file>
            index.htm
        </welcome-file>
  </welcome-file-list>
</web-app>
0
 
LVL 1

Author Comment

by:zloy_ochen
ID: 13811992
On my local machine I have tomcat 5 and servlet runs fine too, but my webhost has tomcat 3.2.3 and for some reason I can't get it to run there
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:suprapto45
ID: 13812024
Hi,

Opppss...sorry but I tested it on Tomcat 5 too.

Regards
Dave
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13812036
Hi,

Maybe it could help.

http://www.tek271.com/articles/deploying_servlets_on_tomcat.html

But truly, I cannot see the differences though :).

Regards
Dave
0
 
LVL 11

Expert Comment

by:Manish
ID: 13813975
Post ur address bar text which ur using to call servlet..
0
 
LVL 11

Expert Comment

by:Manish
ID: 13821465
It is working fine in my workspace..!
0
 
LVL 1

Author Comment

by:zloy_ochen
ID: 13821871
Thank you all the problem is solved. All I had to do is remove ServerConfig
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13873030
Well,

Nice to hear that it is solved.

Regards
Dave
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 14631379
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

850 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