How to run servlet

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
LVL 1
zloy_ochenAsked:
Who is Participating?
 
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0
 
suprapto45Commented:
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
 
zloy_ochenAuthor Commented:
<?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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
zloy_ochenAuthor Commented:
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
 
suprapto45Commented:
Hi,

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

Regards
Dave
0
 
suprapto45Commented:
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
 
ManishLeadCommented:
Post ur address bar text which ur using to call servlet..
0
 
ManishLeadCommented:
It is working fine in my workspace..!
0
 
zloy_ochenAuthor Commented:
Thank you all the problem is solved. All I had to do is remove ServerConfig
0
 
suprapto45Commented:
Well,

Nice to hear that it is solved.

Regards
Dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.