• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic doubt in Servlets

 
Jayanth Mathavan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone...
I bought Head First Servlets & JSP book only yesterday. I was just working out the first quick demo in the first chapter of the book. I followed all the steps given in the book for creating the first simple servlet, but am getting an error message in the internet explorer when trying to view the page.Below is the directory structure... and am using eclipse paltform. Please help.
Pelican(project name)
|
|__ src
| |_one
| |_Ch1Servlet.java(file)
|
|
|__ WEB-INF
|_classes
| |_one
| |_Ch1Servlet.class(file)
|
|_web.xml(file)

The Ch1Servlet.java and web.xml are as it was in the book. and this is what i gave in IE for displaying the page. http://localhost:8080/Pelican/Serv

Thanks & Regards,
Jayanth.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jayanth
What error message you are getting?
 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think its the problem of the location of web.xml

web.xml should be placed in WEB-INF directory

and keep classes folder also in WEB-INF directory.

still if you are getting the error please post the error message
 
Jayanth Mathavan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes the web.xml file is located in WEB-INF folder only. and the classes folder is also located in the WEB-INF folder. am getting the following error.

HTTP Status 404 - /Pelican/Serv

--------------------------------------------------------------------------------

type Status report

message /Pelican/Serv

description The requested resource (/Pelican/Serv) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28



Please find the below the code for web.xml and Ch1Servlet.java

+++++++++++++++++++Ch1Servlet.java++++++++++++++++++++++++++++++
/*import javax.servlet.*;*/
package one;
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>" );
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++web.xml++++++++++++++++++++++++++++++
<web-app>
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>one.Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv</url-pattern>
</servlet-mapping>
</web-app>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the space in the servlet name ? "Chapter1 Servlet" ?
 
Abhishek Dharwadkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey no probs there,
I copied the whole thing and tried it out....
here's the output,

HF's Chapter1 Servlet

Mon Aug 07 02:32:56 PDT 2006

Just check your paths correctly

pelican (project)
|
|
|-----WEB-INF
|
|
|-----web.xml
|
|
|-----classes
| |
| |
| |-----one
| | |
| | |
| | |-----Ch1Servlet.class
 
Abhishek Dharwadkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey sorry for the confusion....
I think the posting here eats up all empty spaces so everything comes in a single line...
here is a more clearer picture

pelican <---- WEB-INF(directory), web.xml(file)

WEB-INF <---- one(directory)

one <---- Ch1Servlet.class(file)

Thanks & Regards,
Abhi.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jayanth", we don't have many rules around here but our naming policy is one of them. Not complying with the policy will lead to your account becoming locked. This warning hopefully will prevent that from happening, but some action is required on your part.

Please review the policy here and you can change your Publicly Displayed Name here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic