一般的做法是在session范围内设置一个状态属性,在登陆成功后将该属性设置为成功状态,默认为不成功状态。
在跳转到要检验的页面判断这个属性的value,如果成功状态就OK,不成功就转向fail.jsp

解决方案 »

  1.   

    Response.Cookies[ "user "][ "login "]=true; 
    Response.Cookies[ "user "][ "id "]= "123456 "; 
    Response.Cookies[ "user "][ "Name "]= "张三 "; ASP是这样判断的
      

  2.   

    例如:登陆成功时候设置 request.getSession().setAttribute(login, user);
    然后在每个需要登陆成功才能访问的页面中加入
    <logic:empty name="login">
    跳转到fail.jsp
    </logic:empty>
      

  3.   


    你说的登录时候设置request.getSession().setAttribute(login, user); 这个是在我的login.jsp那页设置?<logic:empty name="login"> 
    跳转到fail.jsp 
    </logic:empty>是添加在哪页?main.jsp?
    麻烦了 我好久没用过session  解释下
      

  4.   

    其实只用判断的话直接resquest就可以了,放到session里面也行,方便
    ------------
    群19389265 JAVA之家
      

  5.   

    写一个过滤器Filter你说的登录时候设置request.getSession(true).setAttribute("login", user);public class LoginFilter implements Filter{
        public void doFilter( ServletRequest request ,ServletResponse response ,FilterChain chain )
    throws ServletException ,IOException
        {
              HttpServletRequest req = (HttpServletRequest)request; 
                    HttpSession session = req.getSession( true ) ;
    Object obj = session.getAttribute( "login" ) ;
    if( obj != null ){
    chain.doFilter( request , response ) ;
    }else{
    HttpServletResponse res = (HttpServletResponse)response ;
    res.sendRedirect( "login.jsp" ) ;
    }}在web.xml中配置<filter>
    <filter-name>loginFilter</filter-name>
    <filter-class>LoginFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>loginFilter</filter-name>
    <url-pattern>/*</url-pattern> <!--写你需要通过登陆才能访问的页面-->
    </filter-mapping>
    <filter>这样你在整个项目上需要登陆后才能访问的页面只需在web.xml中<url-pattern></url-pattern>指明就可以了
      

  6.   

    request.getSession().setAttribute("login", user);放在STRUTS 的ACTION里啊<logic:empty name="login"> 
    跳转到fail.jsp 
    </logic:empty> 是添加在哪页?main.jsp? 
      为了安全起见 是放在每一个需要登陆才能访问到的页面的开始 可以写一个文件 然后include进去过滤器一劳永逸 只需改配置 而不需改那么多页面
      

  7.   

    按照你的方法是可以了实现了那个效果了 但是我打正确的帐号密码进去 还是刷新到登录页面 而不是main.jsp页面 请问下怎么解决
      

  8.   

    不明白你什么意思!
    你说的意思是输入正确帐号没有跳转到main.jsp页面吗?
    如果是这样那你
    在登陆后一定要把user信息保存到session里
    request.getSession(true).setAttribute("login", user);
    出现上述的情况可能是
    Object obj = session.getAttribute( "login" ) ;
    这句的obj == null;
    你再检查下
      

  9.   

    在你action判断登陆成功后 在return mapping之前加入
    request.getSession(true).setAttribute("login", user);