我为所有jsp页面创建了过滤器,允许在远程用户不为空且允许用户时重定向页面。代码如下
public void doFilter(final ServletRequest request,
final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
String ssoUser = null;
String fullURL = null;
boolean isUserAuthorized = false;
try {
ssoUser = ((HttpServletRequest) request).getRemoteUser();
String queryString =((HttpServletRequest)request).getQueryString();
if(queryString!=null){
fullURL = ((HttpServletRequest)request).getRequestURL().append("?").append( queryString).toString();
}
else{
fullURL = ((HttpServletRequest)request).getRequestURL().toString();
}
//want to forward if correct this condition
if(ssoUser!=null){
if(isUserAuthorized(ssoUser))
request.getRequestDispatcher(fullURL).forward(request, response);
}
chain.doFilter(request, response);
} catch (Exception e) {
}
的web.xml
<filter>
<filter-name>UserFilter</filter-name>
<filter-class>com.filter.UserFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UserFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
它将检查用户并进行身份验证,但在成功验证后无法转发页面。
请建议。
答案 0 :(得分:1)
发货后添加退货
if(ssoUser!=null){
if(isUserAuthorized(ssoUser))
request.getRequestDispatcher(fullURL).forward(request, response);
return; // added a return
}