Link 不重定向

Link doesn't redirect

我想为我的申请实现一个注册页面。首先,我定义了一个身份验证过滤器,当没有设置用户或请求页面不在 public

下时,它将每个请求重定向到我的 login.xhtml
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession ses = req.getSession(false);
// Proceed if user is logged in or its a public page
String requestURI = req.getRequestURI();
if (requestURI.indexOf("/login.xhtml") >= 0 
    || (ses != null && ses.getAttribute("username") != null)
    || requestURI.indexOf("/public/") >= 0)
  chain.doFilter(request, response);
else {
  res.sendRedirect(req.getContextPath() + "/login.xhtml");
}

在我的登录页面上,我有一个 link 到 /public/signup

<h:link value="Signup"  oncklick="/public/signup.xhtml"/>

当我调试时,我可以看到我在 AuthenticationFilter 中的 requestURI 是:http://localhost:8080/appname/login.xhtml 但我预计 http://localhost:8080/appname/public/signup.xhtml

我做错了什么?

"outcome" h:link 的属性用于指定目标资源。

更新您的 h:link 如下:

<h:link value="Signup"  outcome="/public/signup.xhtml"/>