@Override public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,
     HttpServletResponse response) {
  buzzLog.info("-@Override-list---");
  int ret = 1;  HttpSession session = request.getSession();
String  val = (String) session.getAttribute("test");
   if ( val == "yes") {
   super.list(mapping, form, request, response);
   return mapping.findForward(LIST);
  }
val取到的值是空的在用户登录的时候已经setAttribute("test","yes");

解决方案 »

  1.   

    HttpSession session  = request.getServletConext().getSession();
      

  2.   

    判断写错了吧,应该是
    if (val.equals("yes")){
    super.list(mapping, form, request, response);
    return mapping.findForward(LIST);
    }
      

  3.   

    不好意思,想着application了.
    不是==啦...是val.equal("yes")
      

  4.   

    关键是val取到的值是空的 null
      

  5.   

    那就session没获取到拜,在仔细看看你设置session的时候有没错。
    或者session这个会话有没有存在。
      

  6.   

    问题可能出在:
    1 不知道lz判断val是空的,是不是通过这个语句判断的 if ( val == "yes")  还是通过debug判断的,改为 `"yes".equals(val)看看2  HttpSession session = request.getSession();
       改为:
       HttpSession session = ((HttpServletRequest) request).getSession();
       看看!
      

  7.   

    我用val.equals("yes")会报错
    ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/aue].[action]] - <Servlet.service() for servlet action threw exception>
    java.lang.NullPointerException用val == "yes"就没事改为HttpSession session = ((HttpServletRequest) request).getSession(); 
    debug出来的 val is null
      

  8.   

    val.equals("yes")这样会报错就证明了是空的了。你要确定你的页面是在同一个session里啊。
      

  9.   

    看看你前面的页面有没有frame或者你使用了 response.sendRedirect();window.location忘了是不是还在同一会话了。
      

  10.   

    我是在LoginAciton中用return mapping.findForward("login");跳转到的一个用了frame的页面
    是否还是在一个session里不知如何解决这个问题
      

  11.   

    一个页面有几个frame,不同的frame是不同的session.你可以改成iframe试试。
      

  12.   

    我将frame改为了iframe,结果还是一样  null
      

  13.   

    login.jsp
    <html>
    <head>
    <%@ include file="/commons/meta.jsp"%>
    <link href="${ctx}/styles/admin/admin.css" type="text/css"
    rel="stylesheet">
    <title>Login</title>
        <style type="text/css">
    <!--
    .style1 {
    color: #FFFFFF;
    font-weight: bold;
    }
    -->
            </style>
    </head> <body>
            <form action="commons/login.do" method="POST">
            <input type="hidden" name="method" value="loginForm"/>
    <input type="hidden" name="level" value="0"/>   
              <table width="631" height="421" border="0" align="center" background="pics/shot_login.jpg">
                  <tr>
                    <td width="310" height="95">&nbsp;</td>
                    <td width="311">&nbsp;</td>
                  </tr>
                  <tr>
                    <td height="320">&nbsp;</td>
                    <td><table width="100%">
     <tr>
                        <td height="26" colspan='2'><div align="center" class="style1">Login</div></td>
                      </tr>
                      <tr>
                        <td height="27"><span class="style1"> User ID: </span></td>
                        <td><input name='number' type='text' id="number">
                        </td>
                      </tr>
                      <tr>
                        <td height="25"><span class="style1"> Password: </span></td>
                        <td><input name='password' type='password' id="password">
                        </td>
                      </tr>
                      <tr>
                        <td height="30">&nbsp;</td>
                        <td></td>
                      </tr>
                      <tr>
                        <td colspan='2'><div align="center">
                          <input name="submit" type="submit" value="Submit">
                        </div></td>
                      </tr>
                     
                    </table></td>
                  </tr>
                </table>
            </form> </body>
    </html>
    LoginAction.java
    public class LoginAction extends StrutsEntityAction<User,UserManager> { @SuppressWarnings("unused")

    private TypeConvert tct = new TypeConvert(); public void setUserManager(UserManager uManager) {
    this.customerUser = uManager;
    } public ActionForward loginForm(ActionMapping mapping, ActionForm form,
       HttpServletRequest request,
       HttpServletResponse response) { final Log buzzLog = LogFactory.getLog(Constants.BUSINESS_LOG);
    buzzLog.info("--- LoginAction Begin ---"); String userid;
    String passwd;
    int userlevel;
    int ret = 1; userid = request.getParameter("number");
    passwd = request.getParameter("password");
    userlevel = tct.stringToInt(request.getParameter("level")); ret = loginCheck(userid,passwd,request,response); String get = (String) request.getAttribute("login");
    buzzLog.info("-level--"+userlevel+"-- Login number---"+get);
    if (ret==0){
    if ( userlevel== Constants.LEVEL_ADMIN){
    buzzLog.info("---Welcom  administrator----");
    return mapping.findForward("adminlogin");
    }
    else{
    buzzLog.info("---Welcom  user----");
    return mapping.findForward("login");
    }
    }
    else
    return mapping.findForward("loginerror");
    }
             public int loginCheck(String userid, String passwd,HttpServletRequest request,
       HttpServletResponse response){ int ret = 1;
    String hql;
    String passwd2;
    PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
    passwd2 = passwordEncoder.encodePassword(passwd, null); buzzLog.info("---Login Check Begin ---"+passwd2); hql = "from User u where u.number=? and u.passwd=?";
    try {
    List userList = find(hql,userid,passwd2);
    if (userList!=null && userList.size() > 0) { User user = (User) userList.get(0);
    String number=user.getNumber();
    String name=user.getName();
    String zone=user.getZone();
    int level=user.getLevel(); HttpSession session = request.getSession();
    if (session == null)
    buzzLog.info("---session is null ---");
    session.setMaxInactiveInterval(6000);
    session.removeAttribute("login");
    session.removeAttribute("zone");
    session.removeAttribute("level"); request.setAttribute("number", number);
    request.setAttribute("name", name);
    request.setAttribute("zone", zone);
    request.setAttribute("level", level);
    request.setAttribute("login", "yes");
                                         request.setAttribute("test", "yes");
    ret = 0;
    }
    }
    catch(Exception e){
    buzzLog.info("---find error ---");
    e.printStackTrace();
    ret = -1;
    }
    return ret;
    }
    }
      

  14.   

    login 成功后跳转到  index_login.jsp
    <%@ page contentType="text/html;charset=UTF-8" %>
    <%@ include file="/commons/taglibs.jsp" %><html>
    <head>
    <link href="${ctx}/styles/admin/admin.css" type="text/css" rel="stylesheet">
    <%@ include file="/commons/meta.jsp" %>
    <title> Welcome to System.</title>
    <META content=JavaScript name=vs_defaultClientScript>
    </head>
    <SCRIPT>           function switchBar(){
               if (switchPoint.innerText==""){
               switchPoint.innerText=" "
               document.all("leftFrame").style.display="none"
               }else{
               switchPoint.innerText=""
               document.all("leftFrame").style.display=""
               }}
               
               
               function ComfirmExit(action){
                   if(action==1)
                  {
                   myconfirm = confirm("确实要关闭窗口,退出系统吗?");
                 if (myconfirm==true){
            top.location.href="CloseWin.aspx?Action=1";
             }
              }
                  if(action==2)
                {
                   myconfirm = confirm("确实要重新登陆吗?");
                if (myconfirm==true){
           top.location.href="CloseWin.aspx?Action=2";
              }
               }
                   } </SCRIPT><STYLE type=text/css>.navPoint {
    FONT-SIZE: 12px; CURSOR: hand; COLOR: white; FONT-FAMILY: Webdings
    }
    </STYLE><BODY bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0 scroll="no">
    <TABLE id=Table1 height="100%" cellSpacing=0 cellPadding=0 width="100%" 
    border=0>
      <TBODY>
      <TR>
        <TD style="HEIGHT: 50px" align=right colSpan=3>
          <TABLE id=Table3 cellSpacing=0 cellPadding=0 width="100%" border=0>
            <TBODY>
            <TR>
              <TD style="WIDTH: 291px" width=300 
              background="../pics/middle.gif"></TD>
              <TD width="100%" background=../pics/middle.gif></TD>
              <TD align=right width=292 
                background="../pics/middle.gif"><IMG height=68 
                src="../pics/lefttitle.gif" width=292 useMap=#Map 
                border=0></TD></TR></TBODY></TABLE></TD></TR>
      <TR>
        <TD id=leftFrame style="WIDTH: 164px" vAlign=center noWrap align=middle 
        name="leftFrame"><IFRAME id=carnoc style="WIDTH: 164px; HEIGHT: 100%" 
          name=carnoc src="left.jsp" frameBorder=0 
          scrolling=yes></IFRAME></TD>
        <TD style="WIDTH: 9pt" bgColor=#6699cc>
          <TABLE id=Table2 height="100%" cellSpacing=0 cellPadding=0 border=0>
            <TBODY>
            <TR>
              <TD title=打开/关闭全屏 style="WIDTH: 4px; CURSOR: hand; HEIGHT: 100%" 
              onclick=switchBar() vAlign=top 
              background="../pics/middlebgpic.gif"><IMG 
                src="../pics/middletop.gif"> 
                <BR><BR><BR><BR><BR><BR><BR><BR><BR><SPAN id=switchPoint 
                title=打开/关闭全屏></SPAN><IMG src="../pics/middledot.gif"> 
              </TD></TR></TBODY></TABLE></TD>
        <TD style="WIDTH: 100%">
          <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
            <TBODY>
            <TR>
              <TD><IFRAME id=main 
                style="VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 100%" name=main 
                src="main.jsp" frameBorder=0 
                scrolling=yes></IFRAME></TD></TR>
            <TR>
              <TD bgColor=#ff6633 height=20><IFRAME 
                src="../getReference.htm" frameBorder=0 
                width="100%" scrolling=no 
        height="100%">
        </IFRAME>
        </TD>
        </TR>
        </TBODY>
        </TABLE>
        </TD>
        </TR>
        </TBODY>
        </TABLE>
        </FORM>
    </body>
    </html>其中的main.jsp
    <%@ include file="/commons/taglibs.jsp" %>
    <%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><html>
    <head>
    <%@ include file="/commons/meta.jsp" %>
    <link href="${ctx}/styles/admin/admin.css" type="text/css" rel="stylesheet">
    </head>
    <body>
    <c:redirect url="/aue/calendar.do"/>
    </body>
    </html>calendar.do对应的CalendarAction.java
    public class CalendarAction extends StrutsEntityAction<Calendar, CalendarManager> {
    @SuppressWarnings("unused")
    private CalendarManager calendarManager;
    private CustomerManager custm = new CustomerManager(); public void setCalendarManager(CalendarManager calManager) {
    this.calendarManager = calManager;
    } private static final Log buzzLog = LogFactory.getLog(Constants.BUSINESS_LOG); @Override public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    buzzLog.info("-@Override-list---");
    int ret = 1; ret = custm.check("login", request);
    buzzLog.info("-st---"+request.getAttribute("login")); if (ret == 0){
    super.list(mapping, form, request, response);
    // request.setAttribute(getEntityListName(), calendarManager.doFind("6fish"));
    return mapping.findForward(LIST);
    }
    else
    return mapping.findForward("accessDenied"); }
             public int check(String attribute,HttpServletRequest request){
    int ret = 1;
    String val;
    HttpSession session = ((HttpServletRequest) request).getSession();
    if (session == null)
    buzzLog.info("---session is null ---");
    val = (String) session.getAttribute(attribute);
    if (attribute == "login" && val == "yes")
    ret = 0;
      if (attribute == "test" && val == "yes")
      ret = 0;  buzzLog.info("- check--"+attribute+" is "+val+" ret="+ret);
    return ret;
    }
      

  15.   

    我在action 里就是这么接的:
    String str = (String)request.request.getSession().getAttribute("user_id");
    存的时候:
    request.getSession().setAttribute("user_id", "123");
      

  16.   

    不好意思多写了一个request
    应该是:
    我在action 里就是这么接的:
    String str = (String)request.getSession().getAttribute("user_id");
    存的时候:
    request.getSession().setAttribute("user_id", "123");
      

  17.   

    把struts-config.xml贴出来,我怀疑是不是你这个action配置的时候,没有写scope="request"
      

  18.   

    request.setAttribute("login", "yes");
    request.setAttribute("test", "yes");val = (String) session.getAttribute(attribute);-----------------------------------------------------
    存在reqeust中,去session中能取到才怪。-----------------------------------------------------
    <c:redirect url="/aue/calendar.do"/>这句话,重定向了,不在同一session内。
      

  19.   

    确实是这里出的问题request.setAttribute("test", "yes");<c:redirect url="/aue/calendar.do"/>这句话,重定向了在session中可以取到值谢谢诸位