本人编写了消息报送的系统,想在页面中显示登录者报送上来的信息,不知道哪里出错 public ActionForward userdailylist(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response){
String u2 = (String)request.getSession().getAttribute("username"); 
System.out.println(u2); List list = dailyManager.findDailyByUsername(u2);
      request.setAttribute("daily1", list); return mapping.findForward("showuserdaily");
}
请大家帮忙

解决方案 »

  1.   

    不知道楼主哪里报错。
    就你上面的几行代码而言,没什么错误。
    String u2 = (String)request.getSession().getAttribute("username");
    这个最好这样写:(String)request.getSession().getAttribute("username")+"";
    因为你要的是String类型的,否则会有空指针。
      

  2.   

    (String)request.getSession().getAttribute("username")+"";
      

  3.   

    String u2 = request.getSession().getAttribute("username")==null?"":(String)request.getSession().getAttribute("username");这样比较安全
      

  4.   

    严重: Servlet.service() for servlet action threw exception
    javax.servlet.jsp.JspException: Cannot find bean: "userdaily" in any scope
    at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:935)
    at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:232)
    at org.apache.jsp.showuserdaily_jsp._jspService(showuserdaily_jsp.java:146)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
      

  5.   

    jsp文件是这样的:
    <%@ page language="java" pageEncoding="GBK"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html lang="true">
      <head>
        <html:base />
        
        <title><%=session.getAttribute("username") %>的日志</title> <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      <h2 align="center"><font color="blue"><%=session.getAttribute("username") %>的日志</font></h2>
        <div align="center"> <table align="center" bgcolor="pink" border="1px" cellspacing="0" cellpadding="10" width="600" height="120">
    <tr>
    <th>
    <html:link action="toAddDaily">添加日志</html:link>
    </th>
    <td></td>
    <td></td>
    </tr>
    <tr bgcolor="yellow">
    <th>
    日志标题
    </th>
    <th>
    日志内容
    </th>
    <th>
    操作
    </th>
    </tr>
    <logic:iterate id="daily1" name="daily1">
    <tr bgColor=#E4E8EF>
    <td>
    <bean:write name="daily" property="title"/>
    </td>
    <td>
    <bean:write name="daily" property="content"/>
    </td>
    <td>
    <table align="center">
    <tr>
    <th>
    <html:link action="/daily?method=update&dailyid=${daily.dailyid}">修改</html:link>
    </th>
    <th>
    <html:link action="/daily?method=delete&dailyid=${daily.dailyid}">删除</html:link>
    </th>
    <th>

    </th>
    </tr>
    </table>
    </td>
    </tr>
    </logic:iterate>
    </table>

    </div>
    <br>
    <br>
    <div align="center">
    <html:link action="toMain">返回主页</html:link>
    </div>

      </body>
    </html:html>
    前面的错误是Servlet.service() for servlet action threw exception
    javax.servlet.jsp.JspException: Cannot find bean: "daily1" in any scope,忘记改了,不好意思,请大家指教
      

  6.   

    Cannot find bean: "daily1" in any scope,错误是很明显啊,不过看你贴出来的代码里又有往requestScope中设置这个daily1集合。request.setAttribute("daily1", list); 
    这里你看看你的list有没有值啊,不会是null吧?<logic:iterate id="daily1" name="daily1">
    这里明明定义的是daily1,为何后面的代码使用的又是daily呢?(<bean:write name="daily" property="title"/>

    Repeat the nested body content of this tag over a specified collection. Repeats the nested body content of this tag once for every element of the specified collection, which must be an Iterator, a Collection, a Map (whose values are to be iterated over), or an array. The collection to be iterated over must be specified in one of the following ways:As a runtime expression specified as the value of the collection attribute. 
    As a JSP bean specified by the name attribute. 
    As the property, specified by the property, of the JSP bean specified by the name attribute. 
    The collection to be iterated over MUST conform to one of the following requirements in order for iteration to be successful:An array of Java objects or primitives. 
    An implementation of java.util.Collection, including ArrayList and Vector. 
    An implementation of java.util.Enumeration. 
    An implementation of java.util.Iterator. 
    An implementation of java.util.Map, including HashMap, Hashtable, and TreeMap. NOTE - See below for additional information about accessing Maps. 
    Normally, each object exposed by the iterate tag is an element of the underlying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:key - The key under which this item is stored in the underlying Map. 
    value - The value that corresponds to this key. 
    So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:<logic:iterate id="element" name="myhashtable">
    Next element is <bean:write name="element" property="value"/>
    </logic:iterate> 
    If the collection you are iterating over can contain null values, the loop will still be performed but no page scope attribute (named by the id attribute) will be created for that loop iteration. You can use the <logic:present> and <logic:notPresent> tags to test for this case.
      

  7.   

    谢谢lovebaylong,正是list中的值为null,分给你了