1.struts.xml
2.action
3.success.jsp
4.student.java
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <package name="hello" extends="struts-default">
- <action name="Hello" class="edu.jlu.hgd.Hello">
- <result name="success">success.jsp</result>
- </action>
- </package>
- </struts>
- package edu.jlu.hgd;
- import java.util.ArrayList;
- import java.util.List;
- import com.opensymphony.xwork2.ActionSupport;
- public class Hello extends ActionSupport{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private List<Student> list=new ArrayList<Student>();
- @Override
- public String execute() throws Exception {
- // TODO Auto-generated method stub
- list.add(new Student("hgd",1));
- list.add(new Student("wjh",2));
- list.add(new Student("lx",3));
- return SUCCESS;
- }
- public List<Student> getList() {
- return list;
- }
- public void setList(List<Student> list) {
- this.list = list;
- }
- }
- <%@page contentType="text/html; charset=utf-8"%>
- <%@ taglib prefix="s" uri="/struts-tags"%>
- <html>
- <body>
- <table>
- <s:iterator id="a" value="list">
- <tr>
- <td>
- <s:property value="%{num}"/>
- <script type="text/javascript">
- document.write('${a.name}');
- </script>
- </td>
- </tr>
- </s:iterator>
- </table>
- </body>
- </html>
- package edu.jlu.hgd;
- public class Student {
- private String name;
- private int num;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getNum() {
- return num;
- }
- public void setNum(int num) {
- this.num = num;
- }
- public Student() {
- // TODO Auto-generated constructor stub
- }
- public Student(String name, int num) {
- this.name = name;
- this.num = num;
- }
- }