Bookmark Topic Watch Topic
  • New Topic

2 Servlet Contexts in Single Appication?

 
Rajendra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,

I have a basic question about servlets.

1) Can we have multiple ServletContexts in a single web application??
If yes then what is meant by ServletContext is per web application in HFSJ???

2)Can we map 2 different URL's to same Servlet Class??? If yes how can do???

Thanks,
Rajendra.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not crosspost.
http://www.coderanch.com/t/362950/Servlets/java/Servlet-Contexts-Single-Appication
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Rajendra:
Hi All,

I have a basic question about servlets.

1) Can we have multiple ServletContexts in a single web application??
If yes then what is meant by ServletContext is per web application in HFSJ???

2)Can we map 2 different URL's to same Servlet Class??? If yes how can do???

Thanks,
Rajendra.



You can have multiple ServletContexts in the web application only in distributed environment, that is, the container is distributed in more than one JVM and the application is marked as distributable. In this case, Each JVM has ite own ServletContext Object. But the context parameters are same for all the Servlet Context as thease are set at the time of initialization and parameters are red-only.

We can assign different URL to servlet by using multiple <servlet-mapping> with the same servlet name in web.xml.



<web-app ... >
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>mypackage.MySerclet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/servlet1/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>



Thanks
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing this thread as a crosspost duplicate.

"Rajendra", welcome to the ranch. I see that Ulf pointed out in your other thread that your display name does not match our policy here. Please take a few moments to read the Javaranch naming policy. After reading the policy, you can change your name here. We try to be friendly around here but we do have our rules, and not following the naming policy can result in having your account deleted.
 
    Bookmark Topic Watch Topic
  • New Topic