aspose file tools*
The moose likes Tomcat and the fly likes Change in servlet-class & servlet-name in  web.xml not reflected? Why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Change in servlet-class & servlet-name in  web.xml not reflected? Why?" Watch "Change in servlet-class & servlet-name in  web.xml not reflected? Why?" New topic
Author

Change in servlet-class & servlet-name in web.xml not reflected? Why?

suresh pillai
Greenhorn

Joined: Oct 30, 2003
Posts: 23
Hi,
I started the tomcat and pulled up the HelloWorldServlet on the browser.
After that I shut it down and opened the web.xml for that application and changed the servlet-name and servlet-class element to 'httpTest'.
I also put the httpTest.class file in the folder webapp>AppFolder>WEB-INF>classes.
Now when I opened a new browser and refreshed the previous URL it still pulled up HelloWorlServlet. And the new URL with httpTest will not load anything- gives 404 error.
Can any one explain me why is it doing that?
thanks in advance.
suresh
SCJP 1.4
Preeti Patil
Greenhorn

Joined: Nov 27, 2003
Posts: 10
Hi ..
I am also facing the same problem..only diff is i have used Eclipse IDE with Lomboz plugin...
If any one has solution for this...ps let me know.....
Preeti
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Now when I opened a new browser and refreshed the previous URL it still pulled up HelloWorlServlet. And the new URL with httpTest will not load anything- gives 404 error.

I am going to guess that you are using a URL with the /servlet/ syntax and that the web application has the "invoker" servlet turned on. In that case, Tomcat is totally ignoring the web.xml because it sees "/servlet/" and routes the request through the invoker servlet.
Bill
suresh pillai
Greenhorn

Joined: Oct 30, 2003
Posts: 23
Yes... The invoker is on and Iam trying to access using servlet/servName
Now what would be the solution for the tomcat to use the web.xml for each webapp than to use the invoker???
Please help...
thanks,
suresh
SCJP 1.4
suresh pillai
Greenhorn

Joined: Oct 30, 2003
Posts: 23
Hi Preeti,
I have figured out the problem.
I guess we were using the invoker which was preventing the webapp's web.xml from being used for servlet loading[This is implicit loading].
Now if we want to use the explicit loading then we have to add the '<servlet-mapping>' element in our web.xml. So that when you request the servlet using http://servername ort#/webappName/<url-pattern>(as mentioned in web.xml for each servlet) it will use the web.xml file inside the webApp/WEB-INF/ folder to load the servlet.
FYI my web.xml looks like:-
//--------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>surtest</servlet-name>
<servlet-class>tester.surtest</servlet-class>
</servlet>
<servlet>
<servlet-name>logintest</servlet-name>
<servlet-class>log.loger.logintest</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>surtest</servlet-name>
<url-pattern>/sur1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>logintest</servlet-name>
<url-pattern>/sur2</url-pattern>
</servlet-mapping>
</web-app>
//--------------------------------------------
Where surtest.class file is located :- webapp/WEB-INF/classes/tester
and logintest.class is located :-webapp/WEB-INF/classes/log/loger
You will invoke the servlet using :-
http://servername ort#/webapp/sur1 &
http://servername ort#/webapp/sur2
Do not worry about uncommenting/commenting the invoker. I just left it uncommented. You don't even need to add the contextpath in server.xml.
Hope that help... You can refer to this document in case you get stuck
http://test.javaranch.com/wiki/view?InvokerServlet
suresh
SCJP 1.4
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
OK. I see what did you say but I still have the same problem above. Both comment and uncomment invoker I can't use servlet-mapping and get error 404. Why???
Preeti Patil
Greenhorn

Joined: Nov 27, 2003
Posts: 10
Hi Suresh..
whatever u have posted on the JavaRanch ...really i got out of the problem..
The only mistake i was making was... of URL pattern for servlet........
Thanks a lot ...
Preeti
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Surasak - maybe you better post the web.xml you are trying to use and the URL you are using to address it.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Change in servlet-class & servlet-name in web.xml not reflected? Why?