quarks
quarks

Reputation: 35276

Redirect request with JSP

How do I redirect a request with JSP with the path also forwarded?

Example:

my-domain.com/abc to www.other-domain.com/abc

Where 'abc' would be the request path. Also it is possible to also forward query parameters and fragment identifiers?

Upvotes: 1

Views: 199

Answers (2)

Mark Thomas
Mark Thomas

Reputation: 16615

You can't redirect fragment identifiers as they aren't passed to the server.

To do this in JSP you'll want something like the following:

<%
response.sendRedirect("http://www.other-domain.com" +
                       request.getContextPath() +
                       request.getServletPath() +
                       (request.getQueryString() == null ?
                           "" :
                           "?" + request.getQueryString())
%>

Upvotes: 1

fjtorres
fjtorres

Reputation: 276

Use HttpServletResponse:

response.sendRedirect(location)

Upvotes: 0

Related Questions