I didn t make it work with the solution proposed, here s what i found :
(Using spring 3.1).
您的职衔:
CharsetFilter implements Filter {
@OVerride public void doFilter(ServletRequest request, ServletResponse response, FilterChain next) throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
if (hsr.getUserPrincipal() == null) {
HttpSession session = hsr.getSession();
if (!(hsr == null)) {
logger.info("path : " + hsr.getPathInfo());
session.setAttribute("beforeLoginUrl", hsr.getPathInfo());
}
}
}
之后,您的网页xml宣布:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>charsetFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharsetFilter</filter-name>
<filter-class>com.ent.foo.CharsetFilter</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
之后,在成功登录后,在你回旋转时,HttpSession返回:
@RequestMapping(value = "successful")
public void showSuccessfulogin (HttpSession session) {
String redirectUrl = (String) session.getAttribute("beforeLoginUrl");
if (redirectUrl != null) {
session.removeAttribute("beforeLoginUrl");
return "redirect:" + redirectUrl;
}
return "redirect:/";
}
这里,你在工作上站得住脚,但youll必须检查。
hsr.getPathInfo()
and see if it ends with .css or .js, etc...
Also if the login fail you ll should see if session attribute is already set and see any others special case !
此前,我的过滤器曾用于对图f-8的所有投入/产出进行格式。
希望会有所助益。