alex
alex

Reputation: 123

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.

Upvotes: 0

Views: 2462

Answers (2)

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");
}

Upvotes: 2

alex
alex

Reputation: 123

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.

Upvotes: 0

Related Questions