有谁能告诉我struts是怎么把后台(action里面的数据)的数据传送到前台的
比如:
我在后台(action)给一个变量String mylist赋值了。现在想在前台显示
比如
<s:text name="mylist" />
我用了好几种方式显示都不行
方式一:<s:text name="%{mylist}" />
方式二:<s:text name="mylist" />
方式三:<s:text name="#mylist" />
后台程序如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package org.database;import com.opensymphony.xwork2.ActionSupport;
public class User extends ActionSupport{
public String execute() throws Exception {
setMylist("aaaaa");
return "ERROR";
} private String mylist = null;
public String getMylist() {
return mylist;
}
public void setMylist(String value) {
mylist = value;
}
}
请问我需要怎么设置才能正常显示我后台赋的值?原理是怎么样的?
比如:
我在后台(action)给一个变量String mylist赋值了。现在想在前台显示
比如
<s:text name="mylist" />
我用了好几种方式显示都不行
方式一:<s:text name="%{mylist}" />
方式二:<s:text name="mylist" />
方式三:<s:text name="#mylist" />
后台程序如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package org.database;import com.opensymphony.xwork2.ActionSupport;
public class User extends ActionSupport{
public String execute() throws Exception {
setMylist("aaaaa");
return "ERROR";
} private String mylist = null;
public String getMylist() {
return mylist;
}
public void setMylist(String value) {
mylist = value;
}
}
请问我需要怎么设置才能正常显示我后台赋的值?原理是怎么样的?
request.setAttribute("User",user);jsp页面
<% User user =(User)request.getAttribute("User",User );
%>
<#list people as person>
15: <tr>
16: <td>${person.id}</td>
17: <td>${person.name}</td>
18: <td>${person.lastName}</td>
19: </tr>
20: </#list>
< s:property value ="mylist"/>
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("","");
或用
ActionContext.put("","");
编写了getter()方法,getter()方法是把值传到前台页面的(默认属性范围是request范围)
${mylist}
有没有一个简单的例子可以说明这个问题,比如hello等。
${person.id}
用jstl标签
<c:out value="${person.id}"/>
用java
<%=request.getAttribute("persion").getId()%>
或者
<s:property value="%{#request.mylist}" />
这个难道不行吗?
//框架的标签
<s:iterator name="mylist">
//属性
<s:property name="name">
<s:property name="age">
</s:iterator>
然后在JSP页面中拿去就好了