开发者

Spring MVC -> dependent on URL display welcome page

I have a Spring MVC application (version 3.0.5.RELEASE) and I have this in my mvc-config.xml:

<mvc:view-controller path="/" view-name="welcome"/>

So requests to "/" are forwarded to the welcome view welcome.jsp.

This means in my case, calling the URL http://myproject-test.mydomain.com/ will forward to the welcome.jsp. It's fine, but I have to extend it. Besides the URL http://myproject-test.mydomain.com/, I have the URL http://myproject-anothertest.mydomain.com/. With this URL, the whole application should be the same, except the welcome page.

Calling http://myproject-anothertest.mydomain.com/, I want to have the welcome-test.jsp page instead of the welcome.jsp.

So, how can I do this? I have to know from which subomain (myproject-test or myproject-anoth开发者_C百科ertest) the user calls the site and then show him welcome.jsp or welcome-test.jsp.

Does anyone know how this can be done?

Thank you in advance & Best Regards, Tim.


The tag <mvc:view-controller> maps to ParameterizableViewController

You could inherit your own controller class from its parent, AbstractController, and use the request parameter in method handleRequestInternal to deduce which hostname is being used to access your page, then use the appropriate view.

HTTP request header Host contains (if using HTTP/1.1) the "virtual" server name that is being used to access your page. Older HTTP/1.0 protocol does not have the Host header, and some proxies map traffic to HTTP/1.0, in that case you will not be able to distinguish between the traffic using different names.

In JSP, you could use <%=request.getServerName()%> to access the Host header value. See doc for getServerName.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜