首页 文章

prettyfaces 和 jsf:使用 filter 在 action 类中获取 null 值

提问于
浏览
0

你好我正在使用 prettyfaces 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 值在那里变为空。任何解决方案请提前致谢。

1 回答

  • 1

    它看起来不正确你在做什么。您在登录命令按钮中使用pretty:loggedin作为操作属性。这不会执行任何操作方法,而是重定向到其他映射,而没有任何机会处理用户输入的值。

    您应该在 action 属性中引用一个方法,用于处理登录尝试。如果成功,则此方法应返回pretty:loggedin,这会将用户重定向到新页面。

    我希望这能有所帮助。如果你有更多问题,你应该在 PrettyFaces 论坛上发帖。如果解决问题需要多个 question/response 周期,那么这是一个更好的帮助你的地方。 :)

    http://ocpsoft.org/support/

相关问题