Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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