Link to home
Start Free TrialLog in
Avatar of zloy_ochen
zloy_ochen

asked on

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
Avatar of suprapto45
suprapto45
Flag of Singapore image

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
Avatar of zloy_ochen
zloy_ochen

ASKER

<?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>
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
Hi,

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

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

Nice to hear that it is solved.

Regards
Dave
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial