简体   繁体   中英

Tapestry internal redirection to static page

I just want a Tapestry page to redirect to a static 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM