【问题标题】:How can i implement ServletContextAware interface in struts 1.3.10?如何在 struts 1.3.10 中实现 ServletContextAware 接口?
【发布时间】:2013-12-07 06:07:28
【问题描述】:
正在使用 struts 1.3.10 框架开发 Web 应用程序。
所以,我将在整个应用程序中管理会话(也跨所有 jsp 页面和操作类),然后我在 struts 1.3.10 中搜索会话管理,但我通过使用 Aware 接口获得了 struts2 应用程序的会话管理。
如果可能,如何在 STRUTS 1.3.10 中实现 servletcontextaware 接口(或)使用 struts 1.3.10 实现整个应用程序会话的任何其他方式............
提前致谢。
【问题讨论】:
标签:
java
jsp
struts2
jsp-tags
struts-1
【解决方案1】:
我使用过滤器访问会话以确保整个应用程序的安全性。
在 web.xml 中:
<filter>
<filter-name>SecurityFiltrer</filter-name>
<filter-class>app.filtrer.SecurityFiltrer</filter-class>
</filter>
SecurityFilter.java:
public class SecurityFilter implements Filter {
public SecurityFilter() {
super();
}
public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpSession session = request.getSession();
// DO YOUR STUFF HERE
}
}