• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem with HF's first example pg30 chap1

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stop and start the tomcat.
Try this URL and tell me what is coming up.

http://localhost:8000/ch1/

thanks,

Harish
 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no problem. We all went through those problems.
 
Meenakshi Lakshmanan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
knowledge is the difference between drudgery and strategic action -- tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic