Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet not showing up in Browser

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create my first web app servlet working in a folder I created.

In the past my servlets worked in the tomcat 5.5 examples directory:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB-INF\classes


I have a file in here called HelloWorlda.java and it compiled and showed on my local web browser.

I also edited the web.xml in the WEB-INF as shown:

Now I want to create my own directory path:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jones\WEB-INF\classes\email5
I compiled my new EmailServlet.java from the jones\WEB-INF\classes directory:
javac email5\EmailServlet.java and it compiled.

I copied the web.xml from the servel-examples\WEB-INF directory and edited it as such:

After I put in the url in browser:
http://127.0.0.1:8080/jones/servlet/email5/EmailServlet

I get error:
The requested resource (/jones/servlet/email5/EmailServlet) is not available.

Please advise.

[ July 19, 2006: Message edited by: Joseph Smithern ]
[ July 19, 2006: Message edited by: Joseph Smithern ]
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to map your project path with certain name. In this case by jones as you are using localhost:8080/jones/

open your server.xml and add Context tag within the <Host> tag.



Start sever and open your request uri.

Naseem
[ July 19, 2006: Message edited by: Naseem Khan ]
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I tried as you suggested and still get same "cannot find server" message.

I added this to server.xml:

Here is my url that I tried:
http://127.0.0.1:8080/jones/servlet/email5.EmailServlet


My web.xml in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jones\WEB-INF:



[ July 20, 2006: Message edited by: Joseph Smithern ]
[ July 20, 2006: Message edited by: Joseph Smithern ]
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First time you posted this url

http://127.0.0.1:8080/jones/servlet/email5/EmailServlet

Then second time when you posted the url why you replaced email5/EmailServlet with email5.EmailServlet

Your earlier url was correct. The only thing which you have not done at that time was that configuration of <Context> tag in server.xml

First of all you must understand this very well...

Every Servlet class is mapped with some url pattern

For example, your email5.EmailServlet is mapped with url pattern /servlet/email5/EmailServlet.

So while making a request to this servlet instance, url pattern will be used something like this...

http://localhost:8080/jones/servlet/email5/EmailServlet

Suppose url pattern is /Joseph then you url will be

http://localhost:8080/jones/Joseph

Hope it will sort out your problem

Naseem
[ July 21, 2006: Message edited by: Naseem Khan ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joseph Smithern:

<Context path="/jones" docBase="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jones" reloadable="true" debug="0"/>

....


If you're putting your webapp under the "webapps" directory Tomcat will deploy it for you automatically. There is no need to add an entry to server.xml.
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this:

http://localhost:8080/jones/servlet/email5/EmailServlet

with this in my web.xml

I have tried this:


and I put the context path in my server.xml within the host tag.

It still gives me the error:
type Status report

message /jones/servlet/email5/EmailServlet

description The requested resource (/jones/servlet/email5/EmailServlet) is not available.

If I put the EmailServlet in my servlet classes directory it works:
http://127.0.0.1:8080/servlets-examples/servlet/EmailServlet

Please advise.

[ July 22, 2006: Message edited by: Joseph Smithern ]
[ July 22, 2006: Message edited by: Joseph Smithern ]
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<servlet>
<servlet-name>email5/EmailServlet</servlet-name>
<servlet-class>email5/EmailServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>email5/EmailServlet</servlet-name>
<url-pattern>/servlet/email5/EmailServlet</url-pattern>
</servlet-mapping>



This time your web.xml's servlet-class entry is wrong if its not a typo mistake. I have put that thing in bold.

your servlet entry should be like this...



Here are few things which you must remember...

  • servlet-class tag provides the fully qualified class name of servlet. It must be like pkg1.pkg2.ClassName e.g., email5.EmailServlet in your case.
  • With /servlet/email5/EmailServlet url-pattern, your url should be as you posted http://localhost:8080/jones/servlet/email5/EmailServlet. That is correct.
  • <servlet-name> tag could be anything. Important thing is both the servlet-name one defined in <servlet> and second in <servlet-mapping> must match e.g., EmailServlet here



  • Naseem
     
    Joseph Smithern
    Ranch Hand
    Posts: 89
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Naseem,

    It works and I thank you for your patience and time!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic