Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
suresh pillai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surasak - maybe you better post the web.xml you are trying to use and the URL you are using to address it.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic