Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

2 Servlet Contexts in Single Appication?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not crosspost.
https://coderanch.com/t/362950/Servlets/java/Servlet-Contexts-Single-Appication
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic