取不到值

hua6612 2011-06-21 06:17:36
<table>
<tr><th>subject</th><th>content</th></tr>
<s:property value="fld1"/>

<s:iterator value="msglist" id="msg">
<td><s:property value="subject"/></td>
<td><s:property value="content"/></td>
<td></td>

</s:iterator>
</table>


在action里显示msglist是存有值的。为什么JSP页面取不到了
...全文
372 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaluhe003 2011-06-21
  • 打赏
  • 举报
回复
的确是 你重复定义了 msglist 但是你在jsp上 写的也有问题 不要加上ID 把ID去掉就可以了
<table>
<tr><th>subject</th><th>content</th></tr>
<s:property value="fld1"/>

<s:iterator value="msglist">
<td><s:property value="subject"/></td>
<td><s:property value="content"/></td>
<td></td>

</s:iterator>
</table>

hua6612 2011-06-21
  • 打赏
  • 举报
回复
谢谢。原来如此
xinghen88 2011-06-21
  • 打赏
  • 举报
回复
你上面是把msglist作为action的属性了,但是你下面有重新定义了这个list对象,所以并没有把值存的action属性的那个msglistzhong,页面上当然获取不到了。把下面List<Msg> msglist = imsgbiz.msgList(user.getId());中的List<Msg>去掉
hua6612 2011-06-21
  • 打赏
  • 举报
回复
这个我有的。
完整的Action是下面这个
package com.web.struts2.aciton;

import java.util.List;
import java.util.Map;

import org.apache.struts.action.ActionRedirect;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sun.org.apache.regexp.internal.recompile;
import com.web.biz.IMsgBiz;
import com.web.persistence.hibernate.pojo.Msg;
import com.web.persistence.hibernate.pojo.Umuser;

public class MsgListAction extends ActionSupport implements ModelDriven<Umuser>{
private Umuser model = new Umuser();
private IMsgBiz imsgbiz;
private List<Msg> msglist;
private String fld1;

public final String getFld1() {
return fld1;
}
public final void setFld1(String fld1) {
this.fld1 = fld1;
}
public Umuser getModel() {
// TODO Auto-generated method stub
return model;
}
public IMsgBiz getImsgbiz() {
return imsgbiz;
}
public void setImsgbiz(IMsgBiz imsgbiz) {
this.imsgbiz = imsgbiz;
}
@Override
public String execute() throws Exception {
// ActionContext context = ActionContext.getContext();
// Map params = context.getParameters();
// String username = (String)params.get("username");
fld1="abc";
// System.out.println(username+">>");
Umuser user = (Umuser) ActionContext.getContext().getSession().get("user");
System.out.println(user.getId());
// ServletActionContext.getRequest().setAttribute("msglist", msglist);
List<Msg> msglist = imsgbiz.msgList(user.getId());
System.out.println(">>>>"+msglist);

return SUCCESS;
}
public final List<Msg> getMsglist() {
return msglist;
}
public final void setMsglist(List<Msg> msglist) {
this.msglist = msglist;
}



}
空白-键 2011-06-21
  • 打赏
  • 举报
回复
List<Msg> msglist = imsgbiz.msgList(user.getId());
你这样子当然是取不到的,你应该把msglist 设为action的一个属性


public XXAction ... {
private List<Msg> msglist;

getMsglist..
setMsglist..

}
hua6612 2011-06-21
  • 打赏
  • 举报
回复
2楼
用了还是取不到= =
abc
subject content
hua6612 2011-06-21
  • 打赏
  • 举报
回复
action:public String execute() throws Exception {
fld1="abc";
Umuser user = (Umuser) ActionContext.getContext().getSession().get("user");
System.out.println(user.getId());
List<Msg> msglist = imsgbiz.msgList(user.getId());
System.out.println(">>>>"+msglist);

return SUCCESS;
}

这里能取到msglist的值
devin_jia 2011-06-21
  • 打赏
  • 举报
回复
<table>
<tr><th>subject</th><th>content</th></tr>
<s:property value="fld1"/>
<s:set name="list" value="msglist" id="list"></s:set>
<s:if test="#list.size>0">
<s:iterator value="#list" var="lit">
<td><s:property value="subject"/></td>
<td><s:property value="content"/></td>
</s:iterator>
</s:if>
</table>
亲努力啊 2011-06-21
  • 打赏
  • 举报
回复
看看action

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧