struts2从action向jsp传参数
生活随笔
收集整理的這篇文章主要介紹了
struts2从action向jsp传参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
struts2從action向jsp傳參數:
?
1.在action類里面的成員變量域那里寫上你要返回給jsp的變量和相應的get? set方法(比如list)..
在execute方法里為list填充了數據..
?
2.直接在jsp調用.
1).加上<%@ taglib uri="/struts-tags" prefix="s" %>標簽
2).<s:iterator value="list">
?? ??? ? <s:property/>
?? ? </s:iterator>
另外如果list里面放的是一個model,例如User(包含有name和password),
則可以:
<s:iterator value="list">
?? ??? ? <s:property value="name"/>
<s:property value="password"/>
?? ? </s:iterator>
?
?
附上簡單的一個例子:
action:
1 private List<String> testnames; 2 3 public List<String> getTestnames() { 4 return testnames; 5 } 6 public void setTestnames(List<String> testnames) { 7 this.testnames = testnames; 8 } 9 10 11 public String getUsers(){ 12 testnames = new ArrayList<String>(); 13 testnames.add("kim"); 14 testnames.add("deng"); 15 16 return SUCCESS; 17 }jsp:
?
1 <%@ page language="java" contentType="text/html; charset=GB18030" 2 pageEncoding="GB18030"%> 3 <%@ taglib uri="/struts-tags" prefix="s" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <s:iterator value="testnames"> 12 <s:property/> 13 </s:iterator> 14 </body> 15 </html>總結
以上是生活随笔為你收集整理的struts2从action向jsp传参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Struts2三种传参方式(从jsp页面
- 下一篇: Struts2 action之间相互跳转