• Post Reply 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 webs apps one class

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys i have a query

if i have 2 separate web apps , mapped to 2 separate urls eg

lousite.com/appone

lousite.com/apptwo

and both of these call the same Servlet class when hit (except the servlet exists in each webapp/WEB_INF/classes dir).

How many servlets are loaded in the container?

is the servlet loaded twice once from each webapp? and does the correct servlet service the correct web app then?

[ August 13, 2007: Message edited by: Louis Moloney ]

[ August 13, 2007: Message edited by: Louis Moloney ]
[ August 13, 2007: Message edited by: Louis Moloney ]
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

1. put the servlet in one webapp.
Lets us say servletmapping url-pattern will be "/serviveFromAppOne"

example put it in appone.
lousite.com/appone

2. lousite.com/apptwo

2.1 declare a filter.
2.2 map it to the url-pattern "/serviveFromAppOne".
2.3 define filter such a way that it will redirect calls
"/appone/serviveFromAppOne".
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Louis!

Is it, this like situation?



And you access the servlet from the browser:

http://localhost:8084/rootcontext/Servlet.do

Thanks,
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srinivasan,

What do you think of the case I mentioned in just above post?



Thanks,
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra,

1. He is having two web-apps
2. wants to call the same servlet from both the web-apps.

like this:
lousite.com/appone/serviceFromAppOne
lousite.com/apptwo/serviceFromAppOne

I wunderstood his query like this.

How you got ?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this way the servlet contexts would be different. So there should not be a
problem because they would be treated as two different servlet (resource).
One would be /appOne and another /appTwo.

You took some redirecting example to forward the request to particular
servlet (resource) (It is Front Controller, Right?).

Is it like that? You please consider my case too. Sorry for hijacking but
I think the problem could be taken in that way too.

My case assumes it is on same web application.

Thanks,
[ August 13, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To the original post, I think two instances of the servlet will be loaded once for each webapp.

Chandra,
In your case when the container finds the first exact match, it will stop, it will ignore the second exact match. So Servlet1 will service the request.

[Christophe : Unnecessary comment removed]

[ August 13, 2007: Message edited by: Promod Mahajan ]
[ August 13, 2007: Message edited by: Christophe Verre ]
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chandra,
I tried your scenario on Tomcat and Servlert2 is servicing the request. So what I said early on without trying it is not right. I would like someone else to try this and confirm. Here is my code

 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I reverse the order in web.xml, Servlet1 is servicing the request. Basically the second one overrides the first one or the last one overrides the previous ones.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

and both of these call the same Servlet class when hit (except the servlet exists in each webapp/WEB_INF/classes dir)


If you are accessing the same class, but in different contexts, this is not the same servlet. The container will hold a different instance of the servlet in each context.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Promod,
Please be careful about your comments. I have removed an unnecessary comment from one of your posts.
This kind of comment is not quite appreciated here. Thank you for your comprehension.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Louis Moloney,

Please respond to replies of your post.
Is it a test for us ?
or
you are facing some problem ?
 
Louis Moloney
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to see if I had 2 webapps
/app1
/app2

both of which have a Servlet (MyServlet.class) in webapp/WEB-INF/classes that was compiled from the same source code (MyServlet.java).

I am using boths apps (eg app1/getMyServlet , app2/getMyServlet).
What i wanted to know is does the container instantiate 2 instances of MyServlet or 1 ?

and if 2 made are they serviced by the correct instance for the webapp.
Christophe Verre and Promod Mahajan have understood this best

ps

Srinivasan I replied this morning 1st thing when i saw the posts
[ August 14, 2007: Message edited by: Louis Moloney ]
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Srinivasan thoyyeti
I feel Thats container Dependant.

Yes it is container dependent. JBoss uses Unified Class Loader, which loads class only once. We can disable this also.


Srinivasan thoyyeti
I don't see any problem in creating Only one instance re-using the same for other web-apps also.

But there are problems. If the servlet reading any context/initial values it wont differ for different application context. It will be same for the server.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Baiju:
I have deleted my previous post.
I felt it very bad.

But there are problems. If the servlet reading any context/initial values it wont differ for different application context. It will be same for the server.



Yes you are right on target.

1. I don't know whether container can handle this scenario with single servlet instance. I didn't ran this scenario yet

2.But the best thing for container is to have one instance of servlet per context.

3.But I am sure one aspect.If I need one servlet re-used for all web-apps, then I am gonna configure it in one web-app context.

and in all other web-apps I will use a filter to redirect calls to that servlet.

[ August 14, 2007: Message edited by: Srinivasan thoyyeti ]
[ August 14, 2007: Message edited by: Srinivasan thoyyeti ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Baiju Varugese:
Hi,

Srinivasan thoyyeti
I feel Thats container Dependant.

Yes it is container dependent. JBoss uses Unified Class Loader, which loads class only once. We can disable this also.


Srinivasan thoyyeti
I don't see any problem in creating Only one instance re-using the same for other web-apps also.

But there are problems. If the servlet reading any context/initial values it wont differ for different application context. It will be same for the server.



But, what if there are classes in two *different* web application residing in the same container happen to have the *same name* ?
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raghavan,

Please remove my comments.
It doesn't sound good to myself.
 
Ranch Hand
Posts: 284
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raghavan Muthu:


But, what if there are classes in two *different* web application residing in the same container happen to have the *same name* ?



Literally form j2ee 1.4 specification:

Any J2EE product must be able to accept a J2EE application delivered as a .ear file or a stand-alone J2EE module delivered as a .jar,.war, or .rar file (as appropriate to its type). If the application is delivered as a .ear, an enterprise bean module devliered as a .jar file, or a web application delivered as a .war file, the deployment tool must be able to deploy the application such that the Java classes in the application are in a separate namespace from classes in other Java applications. Typically this will require the use of a separate class loader for each application.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Louis Moloney:
[qb]hi guys just lookin for an old freind called louis moloney who lived in Ireland.


[ August 24, 2007: Message edited by: kieran duggan ]
[ August 24, 2007: Message edited by: kieran duggan ]

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic