从第一个action中取得settribute的属性值 如下:
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
PersonForm personForm = (PersonForm) form;
Person p = new Person();
p.setId(personForm.getId());
p.setPassword(personForm.getPassword());
if(DAOFactory.getPersonDAOInstance().isLogin(p)) {
request.getSession().setAttribute("uname", p.getName());
return mapping.findForward("suc");
} else {
request.setAttribute("err","用户名或密码错误!!");
return mapping.findForward("fail");
}

}
fail  到了!~  success.jsp页面:<logic:present name="uname" scope="session">
<h2>
登陆成功
</h2>
<h2>
欢迎
<font color="red" size="12"> ${uname} </font>光临留言程序
</h2>

<h3>
<a href="note.do?status=selectall">进入留言管理页面</a>
</h3>
</logic:present>
确实登陆成功了!~~  然后进入 留言管理:  进入下一个action: 

public ActionForward selectall(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
NoteForm noteForm = (NoteForm) form;
System.out.println("--------------");
System.out.println(request.getSession().getAttribute("uname")); //此处 打印出 竟然是 null值!~~ 该怎么解决啊?
try {
request.setAttribute("all", DAOFactory.getNoteDAOInstance().queryAll());
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("list");
}
以下是struts.config.xml  映射配置(光是此段代码的action):
 <action
      attribute="noteForm"
      input="/form/note.jsp"
      name="noteForm"
      path="/note"
      scope="request"
      type="com.wzr.struts.action.NoteAction" parameter="status">
      
      <forward name="list" path="/list_notes.jsp"></forward>
      <forward name="insert" path="/insert.jsp"></forward>
      <forward name="insertdo" path="/insert_do.jsp"></forward>
      </action>
程序运行没有任何错误!~ 但就是得不到了session!~ 请问错误在哪里? 该怎么样解决?

解决方案 »

  1.   

    首先看看你有没有设置session的失效时间
    然后最好是在request.getSession().setAttribute("uname", p.getName());这句话之前把
    p.getName()打印出来看看,是否有值
      

  2.   

    是有值的!~  因为在中间那个jsp页面,   uname  都已经显示出来了!~
    我没有设置session 的失效时间!~ 按理说是不会失效的!~ 不离开页面的话!~
    但是在  System.out.println(request.getSession().getAttribute("uname"));   确实打出来 null !~    我真不知道原因是什么!~
      

  3.   

    如果长时间无响应的话 不离开页面SESSION也会失效啊
      

  4.   


    没有长时间!~  我就是在测试session!~ 可是始终过不去!~~
    会不会是jar包出了问题?.  因为我换过jar包!~我用的是 struts + Hibernate  + mysql   在myEclipse 6.0 里开发的!~  其间!~ jar包出了问题!~ 错误为: javax.servlet.ServletException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not match signer information of other classes in the same package
    之后查出来是commons.collections.jar 和 commons-beanutils.jar  出现了问题!~
    之后更换了jar包!~~
    会不会因此而影响呢?.  可是别的程序全都正常!~ 就session 这块过不去!~~     我始终想不明白!~
    求高手给予解答!!!~~ 不胜感激!!!!
      

  5.   


    中间贴的是jsp页面!~ 是成功了的!~  写错了!~~
      

  6.   

    action中为什么不是public ActionForward execute(……方法?
      

  7.   

    没有覆盖action 里excute方法
      

  8.   

    打印一下两次请求的 Session ID 看看是否一样,System.out.println(request.getSession().getId());
      

  9.   

    To 10,11楼:
    他用的应该是 DispatchAction。
      

  10.   

    request.getSession().setAttribute("uname", p.getName());
    楼主你可以试一下
    HttpSession session = request.getSession();
    以下两种即可
    session.setAttribute("uname", p.getName());
    session.setAttribute("user", p);楼主可以试一下 我这样做过,这种方法好用的!!!
      

  11.   

    收到多谢13楼
    刚才又去看了下DispatchAction