File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes new to tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "new to tomcat" Watch "new to tomcat" New topic
Author

new to tomcat

pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
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


Thanks,<br />Pallavi
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
<servlet-name>Chapter1 Servlet</servlet-name>


Please get rid of space between word..


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
satheesh krishnaswamy
Ranch Hand

Joined: Mar 17, 2004
Posts: 137
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


Regards,<br /> <br />Satheesh.K<br />-------------<br />SCJP 1.4<br />SCWCD 1.4
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
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

Joined: Jul 04, 2003
Posts: 1312
Add your servlet into package,

it will work..
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
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

Joined: Feb 10, 2004
Posts: 182
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

Joined: Jul 04, 2003
Posts: 1312
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
 
 
subject: new to tomcat