• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble Loading my First Servlet

 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I am a beginner to servlets and do require your help in running my servlet.
My doubt is do we require a servlet mapping tag for every servlet. For example in one of the books I have referring..they have created a servlet TestServlet which is the
package com.exampe.web.

They call the servlet by giving the URL: http://localhost:8080/LifeCycle/servlet/TestServlet/.
They haven't mentioned anything about the deployment descriptor.

I tried out the same example.I have created the same package structure and in my web.xml I have added

<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>TestServlet</servlet-name>
<servlet-class>com.example.web.TestServlet</servlet-class>
</servlet>

</web-app>

I have placed the classes in the WEB-INF/classes folder of my root folder and the web.xml under WEB-INF

But still I am not able to list my servlet.

Is there anything missing. Please help me

Nirmal
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you must map the servlet in the deployment descriptor. If you are using an out-dated book, it's probably relying on the now-deprecated invoker.

You must also place all Servlets and other classes in a package other than the default.

Sounds like you need a more up-to-date reference.
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear

Do i need to add the servlet mapping and sevlet tags in web.xml as


<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.example.web.TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/TestServlet </url-pattern>
</servlet-mapping>

Nirmal
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is what i am getting

HTTP Status 404 - /LifeCycle/servlet/SpecialCharServlet/

type Status report

message /LifeCycle/servlet/SpecialCharServlet/

description The requested resource (/LifeCycle/servlet/SpecialCharServlet/) is not available.iv

and in the web.xml i have given it as

<servlet>
<servlet-name>SpecialCharServlet</servlet-name>
<servlet-class>com.example.web.SpecialCharacterServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>SpecialCharServlet</servlet-name>
<url-pattern>/servlet/SpecialCharServlet</url-pattern>
</servlet-mapping>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You went through the trouble to map it in the deployment descriptor, and then ignored the mapping.
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..I ignored the mapping first..then after giving it as mentioned below

<servlet>
<servlet-name>SpecialCharServlet</servlet-name>
<servlet-class>com.example.web.SpecialCharacterServlet</servlet-class>
</servlet>



<servlet-mapping>
<servlet-name>SpecialCharServlet</servlet-name>
<url-pattern>/servlet/SpecialCharServlet</url-pattern>
</servlet-mapping>


I call my servlet as http://localhost:8080/LifeCycle/servlet/SpecialCharServlet/

Still i get the error

type Status report

message /LifeCycle/servlet/SpecialCharServlet/

description The requested resource (/LifeCycle/servlet/SpecialCharServlet/) is not available.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's LifeCycle? Are you sure that it's your application's context path?

Also, have you tried it without the trailing "/"? Please show some effort on your part.
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Bear..LifeCycle is the root of my web application..
 
Nirmal Mukundan
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear..it working...

Actually i was stuck with this..So the doubt i have is if Im calling a servlet by the url

http://localhost:8080/LifeCycle/servlet/SpecialCharServlet

the url-pattern in my web.xml should start from /servlet/SpecialCharServlet. Is this the way..

Nirmal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic