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(HttpServlet Request request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("t ext/html") ;
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servle t</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/TestSe rvlet
Internal Servlet Error:
java.lang.NullPointerExcep tion
at java.lang.ClassLoader.reso lveClass0( Native Method)
at java.lang.ClassLoader.reso lveClass(C lassLoader .java:588)
at org.apache.tomcat.loader.A daptiveCla ssLoader.l oadClass(A daptiveCla ssLoader.j ava:430)
at org.apache.tomcat.loader.A daptiveSer vletLoader .loadClass (AdaptiveS ervletLoad er.java:17 4)
at org.apache.tomcat.core.Ser vletWrappe r.loadServ let(Servle tWrapper.j ava:265)
at org.apache.tomcat.core.Ser vletWrappe r.init(Ser vletWrappe r.java:289 )
at org.apache.tomcat.core.Han dler.servi ce(Handler .java:254)
at org.apache.tomcat.core.Ser vletWrappe r.service( ServletWra pper.java: 372)
at org.apache.tomcat.core.Con textManage r.internal Service(Co ntextManag er.java:81 2)
at org.apache.tomcat.core.Con textManage r.service( ContextMan ager.java: 758)
at org.apache.tomcat.service. connector. Ajp12Conne ctionHandl er.process Connection (Ajp12Conn ectionHand ler.java:1 66)
at org.apache.tomcat.service. TcpWorkerT hread.runI t(PoolTcpE ndpoint.ja va:416)
at org.apache.tomcat.util.Thr eadPool$Co ntrolRunna ble.run(Th readPool.j ava:501)
at java.lang.Thread.run(Threa d.java:484 )
Points will be awarded to a person how will tell me how to make this servlet run.
Thank you
/*
* 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(HttpServlet
throws ServletException, IOException {
response.setContentType("t
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servle
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/TestSe
Internal Servlet Error:
java.lang.NullPointerExcep
at java.lang.ClassLoader.reso
at java.lang.ClassLoader.reso
at org.apache.tomcat.loader.A
at org.apache.tomcat.loader.A
at org.apache.tomcat.core.Ser
at org.apache.tomcat.core.Ser
at org.apache.tomcat.core.Han
at org.apache.tomcat.core.Ser
at org.apache.tomcat.core.Con
at org.apache.tomcat.core.Con
at org.apache.tomcat.service.
at org.apache.tomcat.service.
at org.apache.tomcat.util.Thr
at java.lang.Thread.run(Threa
Points will be awarded to a person how will tell me how to make this servlet run.
Thank you
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-n ame>
<servlet-class>testPack.Te stServlet< /servlet-c lass>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet< /servlet-n ame>
<url-pattern>/TestServlet< /url-patte rn>
</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>
<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-class>testPack.Te
</servlet>
<servlet-mapping>
<servlet-name>TestServlet<
<url-pattern>/TestServlet<
</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>
ASKER
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
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
Maybe it could help.
http://www.tek271.com/articles/deploying_servlets_on_tomcat.html
But truly, I cannot see the differences though :).
Regards
Dave
Post ur address bar text which ur using to call servlet..
It is working fine in my workspace..!
ASKER
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
Nice to hear that it is solved.
Regards
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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