Class WicketSessionFilter
- java.lang.Object
-
- org.apache.wicket.protocol.http.servlet.WicketSessionFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class WicketSessionFilter extends Object implements javax.servlet.Filter
This filter can be used to make the WicketWebSession
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 bothWicketFilter
andWicketSessionFilter
are mapped to the same url pattern, make sure to have the<filter-mapping>
forWicketFilter
first in yourweb.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(); } }
- Author:
- Eelco Hillenius
-
-
Constructor Summary
Constructors Constructor Description WicketSessionFilter()
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
void
doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
void
init(javax.servlet.FilterConfig filterConfig)
-
-
-
Constructor Detail
-
WicketSessionFilter
public WicketSessionFilter()
Construct.
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
- Specified by:
init
in interfacejavax.servlet.Filter
- Throws:
javax.servlet.ServletException
- See Also:
Filter.init(javax.servlet.FilterConfig)
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
- Specified by:
doFilter
in interfacejavax.servlet.Filter
- Throws:
IOException
javax.servlet.ServletException
- See Also:
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
-
destroy
public void destroy()
- Specified by:
destroy
in interfacejavax.servlet.Filter
- See Also:
Filter.destroy()
-
-