Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new to tomcat

 
pallavi utukuri
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new to tomcat only used wsad.....plz help me out here

created a servlet named Ch1Servlet and kept its class file under
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF\classes

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Ch1Servlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html><body><h1 align=center>HF Chapter1</h1>"+
"<br>"+today+"</body></html>");
}
}


created an xml file name web.xml in
C:\Program Files\Apache Group\Tomcat 4.1\webapps\ch1\WEB-INF

<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"
web-app_4_1.xsd"
version="4.1.30">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>


http://localhost:8080/ch1/Serv1 give the folling error

HTTP Status 404 - /ch1/Serv1

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

type Status report

message /ch1/Serv1

description The requested resource (/ch1/Serv1) is not available.


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

Apache Tomcat/4.1.30


its not under any package and used full path for Servlet-class also
but it didnt work
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<servlet-name>Chapter1 Servlet</servlet-name>


Please get rid of space between word..
 
satheesh krishnaswamy
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pallavi,
Actually it is the good practice to place the Servlets program within a package.If you did not specify any package then the Servlets will take the default package.Hence while deploying the server will look for the source in that package only and hence the 404 Status Error is coming.And also while writing web.xml file you should be careful in specifying the class name because everything is case sensitive.
Bye
Regds
Satheesh.K
 
pallavi utukuri
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got rid of the space
<servlet-name>Chapter1 Servlet</servlet-name>
and checked the case also
still it isint working
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add your servlet into package,

it will work..
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ppl,

I have some clarifications, reg this and would be happy if it is clarified.
Is it mandatory we place the servlet inside a package?

I have servlets, in the web-inf\classes and they work fine? So, what's the root cause of the error Pallavi is getting?

Cheers,
Swamy
 
pallavi utukuri
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i root cause of my error turned out to me problem with Tomcat....i reinstalled it and did some changes with web.xml and server.xml........thats it my coding is working fine.......and noo need of any packages......

and the following is correct noo need to get rid of the space
<servlet-name>Chapter1 Servlet</servlet-name>

i install in a directory without spaces.. like d:\Tomcat4.1
dont know if it solved the prob....but Tomcat do gives lot of troubles when newly installed...well at least for me
Thank u all for helping
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramaswamy Srinivasan:
Hi ppl,

I have some clarifications, reg this and would be happy if it is clarified.
Is it mandatory we place the servlet inside a package?

I have servlets, in the web-inf\classes and they work fine? So, what's the root cause of the error Pallavi is getting?

Cheers,
Swamy



I think, this will help you to understand How-to classloading of Tomcat.

I'm reference to Tomcat 5.0 Documentation

As mentioned above, the web application class loader diverges from the default Java 2 delegation model (in accordance with the recommendations in the Servlet Specification, version 2.3, section 9.7.2 Web Application Classloader). When a request to load a class from the web application's WebappX class loader is processed, this class loader will look in the local repositories first, instead of delegating before looking. There are exceptions. Classes which are part of the JRE base classes cannot be overriden. For some classes (such as the XML parser components in JDK 1.4+), the JDK 1.4 endorsed feature can be used used (see the common classloader definition above). In addition, for the following class patterns, the classloader will always delegate first (and load the class itself if no parent classloader loads it):

javax.*
org.xml.sax.*
org.w3c.dom.*
org.apache.xerces.*
org.apache.xalan.*
Last, any JAR containing servlet API classes will be ignored by the classloader. All other class loaders in Tomcat 5 follow the usual delegation pattern.

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:


Bootstrap classes of your JVM
System class loader classses (described above)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
$CATALINA_HOME/common/classes
$CATALINA_HOME/common/endorsed/*.jar
$CATALINA_HOME/common/lib/*.jar
$CATALINA_BASE/shared/classes
$CATALINA_BASE/shared/lib/*.jar


Reference Website
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/class-loader-howto.html
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic