Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The requested resource (/review/HelloServlet) is not available

 
Elsy Mena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am starting with servlets, jsp and Tomcat.

I am trying to complete a simple HelloServlet example.

I have Tomcat 6.0.18 and the relevant java. I can view the Tomcat main page from http://localhost:8080/

I created the directory structure:

C:\Tomcat\webapps\review\WEB-INF\classes

I have a web.xml file under the WEB-INF directory:


<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/review</url-pattern>
</servlet-mapping>

</web-app>





I have a HelloServlet.java file in the classes folder. I compiled it, and it worked fine.

However, when I try to view the page http://localhost:8080/review/HelloServlet it displays:

type Status report

message /review/HelloServlet

description The requested resource (/review/HelloServlet) is not available.


I don't know why, if I have my web.xml file with the descriptions needed to the servlet. May I did a mistake with the pathname? or there is something else missing?

Thank you very much.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At quick glance I see two mistakes:
1) Classes ought to be placed in packages. There are circumstances wherein packageless servlets work, but you should never make your application dependent on that. That's a bad practice.
2) url-pattern is relative to the context root. So with this configuration your servlet is effectively to be accessed as http://localhost:8080/review/review

I'd to say, go through a decent JSP/Servlet tutorial or book. This all is namely fairly trivial.
 
Elsy Mena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Bauke, it worked with http://localhost:8080/review/review

I did not used a package because it was a little example, but I usually put my classes into packages. Do you know a good JSP/Servlet tutorial or book?


Thank you again.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Head First Servlets & JSP.
 
Elsy Mena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic