public class WicketSessionFilter extends Object implements javax.servlet.Filter
WebSession
instances available to non-wicket servlets.
The following example shows how this filter is setup to for a servlet. You can find the example in the wicket-examples project.
<!-- The WicketSesionFilter can be used to provide thread local access to servlets/ JSPs/ etc --> <filter> <filter-name>WicketSessionFilter</filter-name> <filter-class>org.apache.wicket.protocol.http.servlet.WicketSessionFilter</filter-class> <init-param> <param-name>filterName</param-name> <!-- expose the session of the input example app --> <param-value>FormInputApplication</param-value> </init-param> </filter> <!-- couple the session filter to the helloworld servlet --> <filter-mapping> <filter-name>WicketSessionFilter</filter-name> <url-pattern>/helloworldservlet/*</url-pattern> </filter-mapping> ... <servlet> <servlet-name>HelloWorldServlet</servlet-name> <servlet-class>org.apache.wicket.examples.HelloWorldServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/helloworldservlet/*</url-pattern> </servlet-mapping>Note: If both
WicketFilter
and WicketSessionFilter
are mapped to the same url
pattern, make sure to have the <filter-mapping>
for WicketFilter
first in your
web.xml
.
After that, you can get to the Wicket session in the usual fashion:
if (Session.exists()) { Session wicketSession = Session.get(); }Make sure to test for session existence first, like the HelloWorldServlet does:
public class HelloWorldServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String message = "Hi. " + (Session.exists() ? " I know Wicket session " + Session.get() + "." : " I can't find a Wicket session."); out.println(message); out.close(); } }
Constructor and Description |
---|
WicketSessionFilter()
Construct.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain) |
void |
init(javax.servlet.FilterConfig filterConfig) |
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
Filter.init(javax.servlet.FilterConfig)
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
Filter.doFilter(javax.servlet.ServletRequest,
javax.servlet.ServletResponse, javax.servlet.FilterChain)
public void destroy()
destroy
in interface javax.servlet.Filter
Filter.destroy()
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.