Solved

Calling servlet based on host name.

Posted on 2009-04-06
9
303 Views
Last Modified: 2012-05-06
Hi,
  Is it possible to call servlet based on host name?
How to write this in web.xml?
0
Comment
Question by:Manish
  • 5
  • 4
9 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 24084960
      Hi!

This is configured in the application server itself and the web-app is deployed
to the virtual host that you specify.
Here is how it's configured in Tomcat
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
http://tomcat.apache.org/tomcat-6.0-doc/index.html

What AS are you using ?

Regards,
   Tomas Helgi
0
 
LVL 11

Author Comment

by:Manish
ID: 24084969
it is WAS 6.1
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 24085360
   
Here is the manual for WAS 6.1 Express on LUW
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tcws_plugin_vhost.html

and here is the manual for WAS 6.1 on LUW
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.base.doc/info/aes/ae/tcws_plugin_vhost.html


Then after the deploy of the application go into the app config and change the
host from default_host to the desired virtual host.
Remember to deploy the HTTP plugin afterwards.

Regards,
    Tomas Helgi
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Author Comment

by:Manish
ID: 24085429
Thanks for reply.
I will go through this,
My requirement is like this
  if host is abcd.com then I want to call  /abcdservlet
  if host is defg.com then I want to call  /defgservlet


0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 24085669
Hmmm, if I'm understanding it correctly you want to put one web-app on 2 virtual hosts and
then call 2 different servlets based on what host is requesting service.

Then you could do something like this in combination with what I mentioned earlier.

You could make one servlet that has the context parameters set to what hosts should
be forwarded to what servlet and shared JSP's and other shared servlets should call that servlet only.

http://www.java2s.com/Code/Java/Servlets/Setthecontextparametersinwebxml.htm
http://www.java2s.com/Code/Java/Servlets/Context.htm

Regards,
   Tomas Helgi
0
 
LVL 11

Author Comment

by:Manish
ID: 24085873
how to forward from one servlet to another?
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 24086007
Using URL redirect or URL rewrite
See examples
http://www.java2s.com/Code/Java/Servlets/Redirect.htm

Regards,
   Tomas Helgi
0
 
LVL 11

Author Comment

by:Manish
ID: 24086056
If I redirect ,
Then user's url will get change.
Is there anything which will not change URL?

I tried using forward..but it is not working.
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 125 total points
ID: 24086116
hmmm, in this case I'm afraid not.
At least not that I know of.

Regards,
    Tomas Helgi
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now