This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes invoking servlets differently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "invoking servlets differently" Watch "invoking servlets differently" New topic
Author

invoking servlets differently

ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
hello there,
I used web.xml file in tomcat to do servlet mapping , I have directory structure like this on my system,
c:\clients\sun\TestingServlet.class , and
c:\clients\microsoft\TestingServlet.class ,
the sun\TestingServlet generates "reply from sun servlet" text,and microsoft\TestingServlet generates text "reply from microsoft servlet" , I have mapped TestingServlet in web.xml,
so what I am looking for is when I invoke
"http://server:80/servlet/clients/sun/TestingServlet" it should generate "reply from sun servlet" text and when I invoke ,
"http://server:80/servlet/clients/microsoft/TestingServlet" it should generate "reply from microsoft servlet" text.
but whatever url I use to invoke the TestingServlet it only generates "reply from sun servlet" , I am not getting "reply from microsoft servlet" text even though I use "http://server:80/servlet/clients/microsoft/TestingServlet" url to invoke servlet , what should I do get text accordingly servlets in certainn directory.
thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
I think we would need to see the actual web.xml entries for those two servlets to figure this out.
ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
here is the entries in web.xml file where servlet mapping takes place. I have used the same servlet name but they are in different directories , one in c:\clients\sun\TestingServlet that prints reply from sun
other in c:\clients\microsoft\TestingServlet that prints reply from microsoft , but when I type http://server:8080/servlet/TestingServletsun or http://server:8080/servlet/TestingSErvletmicrosoft both of them prints "reply from sun" , how can I get reply from microsoft servlet .
<servlet>
<servlet-name>
TestingServletsun
</servlet-name>
<servlet-class>
TestingServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>
TestingServletmicrosoft
</servlet-name>
<servlet-class>
TestingServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
invoker
</servlet-name>
<url-pattern>
/servlet/*
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
jsp
</servlet-name>
<url-pattern>
*.jsp
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
TestingServletsun
</servlet-name>
<url-pattern>
/servlet/clients/sun/
</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>
TestingServletmicrosoft
</servlet-name>
<url-pattern>
/servlet/clients/microsoft/
</url-pattern>
</servlet-mapping>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
If it was me, I would try the url pattern:
<url-pattern>/clients/microsoft/</url-pattern>
without the word servlet in there.
I think that this:
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
is what is controlling the response.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: invoking servlets differently