org.exist.http.servlets
Class RedirectorServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.exist.http.servlets.RedirectorServlet
- All Implemented Interfaces:
- Serializable, Servlet, ServletConfig
public class RedirectorServlet
- extends HttpServlet
Servlet to redirect HTTP requests. The request is passed to an XQuery whose return value
determines where the request will be redirected to. The query should return a single XML element:
<exist:dispatch xmlns:exist="http://exist.sourceforge.net/NS/exist"
path="/preview.xql" servlet-name="MyServlet" redirect="path">
<exist:add-parameter name="new-param" value="new-param-value"/>
</exist:dispatch>
The element should have one of three attributes: path, servlet-name or
redirect.
If the servlet-name attribute is present, the request will be forwarded to the named servlet
(name as specified in web.xml). Alternatively, path can point to an arbitrary resource. It can be either absolute or relative.
Relative paths are resolved relative to the original request.
The request is forwarded via RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
.
Contrary to HTTP forwarding, there is no additional roundtrip to the client. It all happens on
the server. The client will not notice the redirect.
When forwarding to other servlets, the fields in HttpServletRequest
will be
updated to point to the new, redirected URI. However, the original request URI is stored in the
request attribute org.exist.forward.request-uri.
If present, the "redirect" attribute causes the server to send a redirect request to the client, which will usually respond
with a new request to the redirected location. Note that this is quite different from a forwarding via RequestDispatcher,
which is completely transparent to the client.
RedirectorServlet takes a single parameter in web.xml: "xquery". This parameter should point to an
XQuery script. It should be relative to the current web context.
<servlet>
<servlet-name>RedirectorServlet
<servlet-class>org.exist.http.servlets.RedirectorServlet
<init-param>
<param-name>xquery
<param-value>dispatcher.xql
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RedirectorServlet
<url-pattern>/wiki/*
</servlet-mapping>
- See Also:
- Serialized Form
DEFAULT_USER
public static final String DEFAULT_USER
- See Also:
- Constant Field Values
DEFAULT_PASS
public static final String DEFAULT_PASS
- See Also:
- Constant Field Values
DEFAULT_URI
public static final XmldbURI DEFAULT_URI
DRIVER
public static final String DRIVER
- See Also:
- Constant Field Values
RedirectorServlet
public RedirectorServlet()
init
public void init(ServletConfig config)
throws ServletException
- Specified by:
init
in interface Servlet
- Overrides:
init
in class GenericServlet
- Throws:
ServletException
Copyright (C) Wolfgang Meier. All rights reserved.