File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem with HF's first example pg30 chap1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem with HF Watch "Problem with HF New topic
Author

Problem with HF's first example pg30 chap1

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Hi guys,

This is a repeat question. If you have seen my posting in servlets board pls ignore it. I am just desparate to get an answer and thought this would be a good place to post too.

I remember to have done this exercise before on my computer and gotten the result page, but for some reason it is not working now. Compilation works fine since I put the servlet-api.jar file in the classpath. But when I launch the browser there is this message:
"The requested resource (/ch1/Serv1) not available"

My logs directory does not have any error messages and is empty.

There are only two files in the tomcat directory:

Ch1Servlet.class is in:

c:\tomcat\jakarta-tomcat-5.5.7\webapps\ch1\WEB-INF\classes

web.xml is in:

c:\tomcat\jakarta-tomcat-5.5.7\webapps\ch1\WEB-INF

The url I use is :

http://localhost:8000/ch1/Serv1

and I do see the welcome page if I type http://localhost:8000 (Tomcat is running on port 8000 in my system and I think oracle has taken 8080.)

This is my xml file:

<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_2.4.xsd" version="2.4">
<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>
</sevlet-mapping>
</web-app>

The servlet is:

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

public class Ch1Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)

throws IOException
{
PrintWriter out=response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html>" + "<body>" + "<h1 align=center>HF\'s Chapter1

Servlet</h1>"+"<br>"+today+"</body>"+"</html>");
}
}

What could be the problem? Can somebody help please.

Thank you.


Sue

SCJP 1.2
SCWCD 1.4
SCBCD 5.0
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
Stop and start the tomcat.
Try this URL and tell me what is coming up.

http://localhost:8000/ch1/

thanks,

Harish


SCJP 1.4 | SCWCD 1.4 | SCJD (WIP)
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Originally posted by Harish Yerneni:
Stop and start the tomcat.
Try this URL and tell me what is coming up.

http://localhost:8000/ch1/

thanks,

Harish


Thanks Harish, I did find my mistake. I saw the web.xml file listed when I typed:
http://localhost:8000/ch1
When I clicked on it, the page showed an error message and I figured I misspelt the closing </servlet-mapping> tag.

But even though I corrected the web.xml file, saved in both working and tomcat directory, shutdown and restarted the server and the system, I have the same problem and clicking on the web.xml link on the browser still shows the same mismatched closing tag error message.

One more thing I now noticed in the tomcat server window is this:

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[LocalHost].StandardContext[/ch1]

Where did I go wrong? Why does it not recognize my web.xml?
[ January 18, 2006: Message edited by: Sue Pillai ]
Ben Weng
Greenhorn

Joined: Feb 22, 2005
Posts: 19
Sue,
I had the same error before. If you are sure you've got all errors corrected in web.xml(that error you got, quite likely there is something wrong with the web.xml file), try pack your files in a war file and use Tomcat's manager to deploy it. At least it solved my problem. Drop the corrected web.xml file did not work for me.
Besides, what is your context.xml look like?


-Ben<br />SCJP/SCJD 1.4<br />Certified Sybase DBA
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Originally posted by Ben Weng:
Sue,
I had the same error before. If you are sure you've got all errors corrected in web.xml(that error you got, quite likely there is something wrong with the web.xml file), try pack your files in a war file and use Tomcat's manager to deploy it. At least it solved my problem. Drop the corrected web.xml file did not work for me.
Besides, what is your context.xml look like?


Ben, I dropped the whole example and recreated it this time with different names and deployed it. positively no errors in the DD this time. Still the same error while executing! Since I am still in the first chapter, I have no clue of how to pack my files to a war or deploy in the tomcat's manager. I also did not know what the context.xml does, but I did give a search in the tomcat directory and got 2 of them. One in the conf directory and one in webapps/balancer/meta-inf directory. I have listed the contents for you.

The first one is as follows:

<!-- The contents of this file will be loaded for each web application -->
<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>META-INF/context.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->

</Context>




The second one is:

<!--

Context configuration file for the Tomcat Balancer Web App
This is only needed to keep the distribution small and avoid duplicating
commons libraries

$Id: context.xml,v 1.1 2004/08/26 17:03:34 remm Exp $

-->


<Context privileged="true" antiResourceLocking="false" antiJARLocking="false" />

Hope you or someone else will figure the prob out and get this working for me. I am stuck in chap1 for very long!
Meenakshi Lakshmanan
Greenhorn

Joined: Oct 07, 2005
Posts: 10
try replacing

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2.4.xsd" version="2.4">

in your web.xml with

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2.4.xsd" version="2.4">

this made my program work...i hope it helps.
Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
Extremely sorry Ben, Harish & Meenakshi....I think I am becoming an extreme case of ADD.

It was a stupid stupid mistake on my part. I put the web.xml in the wrong directory, (directly under ch1, instead of ch1/web-inf) and I am looking at writing the exam in a month!

Really sorry for wasting your time.
Ben Weng
Greenhorn

Joined: Feb 22, 2005
Posts: 19
Oh well. I am just happy for you that you figured it out -- which by the way, probably the hardest problem to troubleshoot.
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
no problem. We all went through those problems.
Meenakshi Lakshmanan
Greenhorn

Joined: Oct 07, 2005
Posts: 10
I know how that feels i was stuck with that example for 3 days...once you get that done it will be easier to get the rest done so dont worry, put ur mind to it you will be ready for the exam in a month
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with HF's first example pg30 chap1