0

我已经为所有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>

它将检查用户并进行身份验证,但成功验证后无法转发页面。

请建议。

4

1 回答 1

1

发货后添加退货

if(ssoUser!=null){
            if(isUserAuthorized(ssoUser))
            request.getRequestDispatcher(fullURL).forward(request, response);
            return; // added a return
        }
于 2012-12-13T12:05:26.437 回答