嗯,如果需要登陆的才能进行的操作页面可以加一个这样的验证,如果验证不通过,自动调转到登陆页面。可以把这个代码写到一个jsp里面,然后需要登陆的页面引用这个jsp即可。也可以用更复杂的spring struts等等。

解决方案 »

  1.   

    顶楼上,用servlet过滤器就可以实现。
    或者可以写一个servlet监听器,对登录的session进行监听。
      

  2.   

    Filter里面做吧
    import java.io.IOException;import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import cc.hotel.login.vo.Person;public class ControlFilter implements Filter {
    private FilterConfig config = null; private String encoding = null; private String forword = null; private String path = null; private boolean bl = true; public void destroy() {
    config = null;
    encoding = null;
    forword = null;
    path = null;
    bl = true;
    } public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    httpRequest.setCharacterEncoding("gb2312"); // 改变请求编码方式
    httpResponse.setCharacterEncoding("gb2312"); // 改变响应编码方式

    path = httpRequest.getServletPath(); // 获得请求路径
    System.out.println(path);
    /*---------------------------权限控制----------------------------------*/
    if (path.endsWith(".jsp") || path.endsWith(".do")) {
    if (path.endsWith("login.jsp") || path.endsWith("login.do")) {
    } else {Person admin = (Person) httpRequest.getSession()
    .getAttribute("person");
    if (admin == null) {
    bl = false;
    }


    }
    }
    /*---------------------------权限控制 end----------------------------------*/
    if (bl) {
    chain.doFilter(request, response);
    } else { // 非法进入系统,返回登陆页面
    bl = true;
    httpRequest.getRequestDispatcher(forword).forward(httpRequest,
    httpResponse);
    }
    }

    public void init(FilterConfig config) throws ServletException {
    this.config = config;
    encoding = config.getInitParameter("gb2312");
    forword = config.getInitParameter("forword");
    }





    }
      

  3.   

    谢谢 ylz2007(天涯浪子)
    同样也谢谢其他人。