• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

I am not able to Run Head First servlet example

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I gone thru other thread about the same error on the forum and didn't find any of the suggestion working.

Please help me .....
I am trying to run Head First Servlet example and from (few other books also)

Detail of plateform:-
OS Windows Vista.
Tomcat 5.5
JRE 1.6
IDE used eclipse and Tomcat is configured in eclipse using •Sysdeo Tomcat Plugin
Directory Structure
C:\Tomcat\Tomcat 5.5
C:\Java\jre

Project Dir

C:\Tomcat\Tomcat 5.5\webapps\ch1
C:\Tomcat\Tomcat 5.5\webapps\ch1\WEB-INF\classes contains Ch1Servlet.class

C:\Tomcat\Tomcat 5.5\webapps\ch1\WEB-INF contains web.xml


Cdoe snippet
Ch1Servlet.java code

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet
{
public void doGet(HttpServletRequest request1, HttpServletResponse response1)
throws IOException, ServletException
{
PrintWriter out = response1.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>" + "<body>" + "<h1 align = center> HF first servlet </h1>" + "<br>" +
today + "</body>" + "</html>");

}

}


web.xml


<?xml version=”1.0” encoding=”ISO-8851-1” ?>
<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>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>


when i try to

http://localhost:8080/ch1/Serv1

type Status report

message /ch1/Serv1

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




I think it should run but don't know if i may be missing...

Tomcat setting
VM arguments

-Dcatalina.base="C:\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0" -Dcatalina.home="C:\Tomcat\Tomcat 5.5" -Dwtp.deploy="C:\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps" -

Please let me know if any other detail is needed.

Regards,


 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First step is to place the servlet in a package other than the default.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the log has only this much

[2011-02-06 01:57:28] [info] Commons Daemon procrun (1.0.2.0) started
[2011-02-06 01:57:28] [info] Service Tomcat5 name Apache Tomcat
[2011-02-06 01:57:28] [info] Service Tomcat5 installed
[2011-02-06 01:57:28] [info] Commons Daemon procrun finished.
[2011-02-06 01:57:28] [info] Commons Daemon procrun (1.0.2.0) started
[2011-02-06 01:57:28] [info] Updating service...
[2011-02-06 01:57:29] [info] Service Tomcat5 updated
[2011-02-06 01:57:29] [info] Update service finished.
[2011-02-06 01:57:29] [info] Commons Daemon procrun finished.
[2011-02-06 01:57:32] [info] Commons Daemon procrun (1.0.2.0) started
[2011-02-06 01:57:32] [info] Updating service...
[2011-02-06 01:57:32] [info] Service Tomcat5 updated
[2011-02-06 01:57:32] [info] Update service finished.
[2011-02-06 01:57:32] [info] Commons Daemon procrun finished.
[2011-02-06 01:57:33] [info] Commons Daemon procrun (1.0.2.0) started
[2011-02-06 01:57:33] [info] Updating service...
[2011-02-06 01:57:33] [info] Service Tomcat5 updated
[2011-02-06 01:57:34] [info] Update service finished.
[2011-02-06 01:57:34] [info] Commons Daemon procrun finished.
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you moved the class to a named package yet?
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah moved to pakage Test
class is now in

C:\Tomcat\Tomcat 5.5\webapps\ch1\WEB-INF\classes\Test


http://localhost:8080/ch1.Test/Serv1

type Status report

message /ch1.Test/Serv1

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


 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Package names should be all lowercase. Did you change the package declaration in the Java source file as well? Did you change the web.xml?

This URL is not correct:

/ch1.Test/Serv1

You don't include the package name in the URL.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package name com.test
class file is at
C:\Tomcat\Tomcat 5.5\webapps\ch1\WEB-INF\classes\com\test

web.xml


<?xml version=”1.0” encoding=”ISO-8851-1” ?>
<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>Chapter1 Servlet</servlet-name>
<servlet-class>com.test.Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>

outcome

http://localhost:8080/ch1/Serv1

no luck

type Status report

message /ch1/Serv1

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

 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Tomcat manager application to ensure that the web app is even running.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot for quickly responding..
I have started today only and don't know how to do it?
Can you please elaberate how I can do that? Till then i will google and try that out? or point me to some quick start link...?
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also do a quick test by putting an index.html file at the context root with something like:and see if you can display it.

But getting the Tomcat manager set up is essential to going forward. See the TomcatFaq for details.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear may be bothering too much.....
I am not getting out of this vicious loop.....
I made following changes as per tomcat faq..
tomcat-user.xml
<role rolename="manager"/>
<user username="bunty" password="jaimatadi" roles="manager"/>
<tomcat-users>
<user name="tomcat" password="tomcat" roles="tomcat" />
<user name="role1" password="tomcat" roles="role1" />
<user name="both" password="tomcat" roles="tomcat,role1" />
<user username="bunty" password="jaimatadi" roles="manager"/>

</tomcat-users>


Then
http://localhost:8080/manager
but still

type Status report

message /manager

description The requested resource (/manager) is not available.

 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try example also ....

http://localhost:8080/servlet/HelloWorldExample

but it also produce same result

type Status report

message /servlet/HelloWorldExample

description The requested resource (/servlet/HelloWorldExample) is not available.

 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, perhaps your Tomcat installation is misconfigured. Until you can get the Tomcat samples working, there's no sense trying to get your own app to work.

Perhaps you should start from scratch and re-install Tomcat 6.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have reinstalled tomcat 6
uncommented from web.xml from CATLINA_HOME

<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

When I put http://localhost:8080/ I am able see welcome message

"If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!"

but subsequently when I try to run example

http://localhost:8080/servlets/servlet/HelloWorldExample

type Status report

message /servlets/servlet/HelloWorldExample

description The requested resource (/servlets/servlet/HelloWorldExample) is not available.

Now i think tomcat is installed properly and configured correctly but still why i am not able to run example

Regards,
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This:

http://localhost:8080/servlets/servlet/HelloWorldExample

does not look like a valid URL.

Also, look at the Tomcat FAQ to set up the Tomcat Manager application. It will tell you whether your web app is even running or not.
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to run all the example but as soon as i try, my servlet it fails with same error. I imported one pakage from some tutorial in eclipse even that one also work fine .....Along with that i login with manager role and checked thing which looks smooth, I don't know where I am missing that something which may make things work for me......I have almost posted everything let me post once again some basic stuff which used

my servlet .....

package coreservlets;

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


public class HelloServlet2 extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello Servlet2</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
}
}


and
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
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">

<servlet>
<servlet-name>Hello Servlet</servlet-name>
<servlet-class>coreservlets.HelloServlet2</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Hello Servlet</servlet-name>
<url-pattern>/hi2</url-pattern>
</servlet-mapping>


</web-app>

output:
http://localhost:8080/test/hi2 or

type Status report

message /test/hi2

description The requested resource (/test/hi2) is not available.

Regards,

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this test you are using in your URL?
 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is name of the project......


 
Bunty Kumar Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear for your help and time.
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doru St, Your post was moved to a new topic. Please be sure to start new topics for your own questions. Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic