• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Calling servlet based on host name.

Hi,
  Is it possible to call servlet based on host name?
How to write this in web.xml?
0
Manish
Asked:
Manish
  • 5
  • 4
1 Solution
 
Tomas Helgi JohannssonCommented:
      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
 
ManishLeadAuthor Commented:
it is WAS 6.1
0
 
Tomas Helgi JohannssonCommented:
   
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ManishLeadAuthor Commented:
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
 
Tomas Helgi JohannssonCommented:
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
 
ManishLeadAuthor Commented:
how to forward from one servlet to another?
0
 
Tomas Helgi JohannssonCommented:
Using URL redirect or URL rewrite
See examples
http://www.java2s.com/Code/Java/Servlets/Redirect.htm

Regards,
   Tomas Helgi
0
 
ManishLeadAuthor Commented:
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
 
Tomas Helgi JohannssonCommented:
hmmm, in this case I'm afraid not.
At least not that I know of.

Regards,
    Tomas Helgi
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now