Tapestry internal redirection to static page
I just want a Tapestry page to redirect to a stati开发者_StackOverflow中文版c page like this :
http://www.myWebSite.com/home/myPage.tml -> http://www.myWebSite.com/static/myStaticPage.html
I try to do this by returning a new URL, but i need to know the web site address for that (http://www.myWebSite.com/). So, i would like to know how to do this without knowing the web site address ?
Thank you.
You can inject (using @Inject) the HttpServletRequest directly in your page directly, without using RequestGlobals, and use its getServerName()
method to get the server name. Not tested:
@Inject
private HttpServletRequest request;
Object onActivate() {
return new java.net.URL("http://" + request.getServerName() " + "/myStaticPage.html");
}
Found : using the RequestGlobals service
String baseUrl = requestGlobals.getHTTPServletRequest().getRequestURL().toString().replaceFirst(requestGlobals.getHTTPServletRequest().getRequestURI(), "");
Just use it to build your URL string put it in a URL instance.
精彩评论