aspose file tools *
The moose likes Servlets and the fly likes issue with web.xml  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "issue with web.xml  " Watch "issue with web.xml  " New topic
Author

issue with web.xml

Babu Singh
Ranch Hand

Joined: Aug 17, 2009
Posts: 78
i have some servlet classes and jsp files.

i made a Servlet class ServletHome.java which work only transfer the control to Vij.jsp. Vij.jsp in turn call a another jsp file Indus.jsp. this jsp transfer the control to another servlet class ServletOne.java which perform
some business logic on some java classes then dispaly the result on same jsp file Indus.jsp from where i called ServletOne.java

i am configuring web.xml.but due to some mistake in web.xml, i am founding exception.

web.xml

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

particularly your servlet-mapping is wrong .
http://jakarta.apache.org/cactus/integration/howto_tomcat.html
Babu Singh
Ranch Hand

Joined: Aug 17, 2009
Posts: 78

please suggest to rectify the web.xml file.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575



<servlet-mapping>
<servlet-name>ServletHome</servlet-name>
<servlet-name>ServletOne</servlet-name> //remove
<url-pattern>/Vij.jsp</url-pattern>
</servlet-mapping>



remove one of the servlet-name. please show some effort . it will help you to solve problem / get knowledge
sujith Acharya
Ranch Hand

Joined: Dec 25, 2006
Posts: 60


Here you are mapping url-pattern to two different servlet name.
Babu Singh
Ranch Hand

Joined: Aug 17, 2009
Posts: 78

i did some change in web.xml


now it deployed. but when i click on the link of ServletHome , it give error Error 404 not found.


ServletHome.java is:


please help.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

How do you triggering the servlet?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12839
    
    5



I really should have a handy cut and paste to say this since it is a common beginner error for people moving from desktop applications to a container hosted environment.

ALL classes in servlets should be in named packages and the class files stored accordingly.
What you have there is a class in the "default" package - a JVM will look for it in the "current" directory. You have no control over the current directory therefore the class is never loaded.

Bill
Babu Singh
Ranch Hand

Joined: Aug 17, 2009
Posts: 78

current directory is Webproject

E:\Webproject\WEB-INF\classes

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61792
    
  67

Perhaps you missed the point: place the Servlets in a non-default package or they won't work.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Babu Singh
Ranch Hand

Joined: Aug 17, 2009
Posts: 78


i placed all servlet classes in a servlet folder under E:\Webproject\WEB-INF\classes

i also placed vij folder under servlet class. vij folder have some java classes. one servlet use this java classes. if i did not place the vij folder under servlet folder one servlet are not compile.

so root for servlets classes is:
E:\Webproject\WEB-INF\classes\servlet

root for java classes is:
E:\Webproject\WEB-INF\classes\servlet\vij

web.xml is:

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

it must be



I do suggest you to *google* about web application structure and make a *Hello World* Servlet
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12839
    
    5
current directory is Webproject

E:\Webproject\WEB-INF\classes


No, you have little to no control over what a servlet container thinks is the "current" directory.

You should become familiar with the official servlet API and the directory structure requirements. Why not start at this Sun/Oracle site instead of flailing around.

Bill
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
Seetharaman Venkatasamy wrote: it must be


Yes, except that I think an incorrect value has been used for the servlet class, so I don't think servlet is actually the package name for the class file - instead, I think the poster placed the url pattern into this field by mistake. I think the poster still doesn't understand the need for packages, or doesn't understand what they are.
Seetharaman Venkatasamy wrote:I do suggest you to *google* about web application structure and make a *Hello World* Servlet

That's good advice. There's good 'getting started' help in the ServletsFaq on the Ranch.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: issue with web.xml