你好,我正在使用漂亮的 jsf2.0 我创建了一个过滤器,它检查每个请求是否用户已登录
@WebFilter(urlPatterns= {"*.xhtml"} , dispatcherTypes = {DispatcherType.REQUEST})
public class Authentication implements Filter {
@Override
public void init(FilterConfig config) throws ServletException {
System.out.println("[Authentication Filter] : init Method");
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
PrettyContext context = PrettyContext.getCurrentInstance(request);
if (!(context.getCurrentMapping().getId().equals("login")) && (session == null || session.getAttribute("username") == null)) {
{
response.sendRedirect(request.getContextPath()+"/login");
}
else {
chain.doFilter(req, res); // Logged-in user found, so just continue request.
}
@Override
public void destroy() {}
}
当我启动 tomcat 服务器时,它加载 login.xhtml 页面 URL 显示在地址栏中 //localhost:8080/MyApp/login 在 login.xhtml 我已经形成了用户名和密码字段
当我使用提交表单时
<p:commandButton ajax="false" value="Login" action="pretty:loggedin" />
当我在操作类中获取值时,那里的值是空的,当我在过滤器中打印 system.out.println loggin 时,看起来两个 URL 正在请求 1./login 2./loggedin 那里的 y 值是空的。任何解决方案请提前感谢。