使用struts2标签需要在页面中添加标签库:
<%@ taglib prefix="s" uri="/struts-tags"%>
后台action代码:
package com.ssh.action;
import java.util.List;
import javax.annotation.Resource;
import com.opensymphony.xwork2.ActionSupport;
import com.ssh.dao.StudentDao;
import com.ssh.dao.impl.StudentDaoImpl;
import com.ssh.entity.Student;
public class StudentAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -3645608660851155268L;
StudentDao studentDao;
public StudentDao getStudentDao() {
return studentDao;
}
public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
}
public List<Student> getList() {
return list;
}
public void setList(List<Student> list) {
this.list = list;
}
List<Student> list;
public String list(){
System.out.println("-------sleep---------");
System.out.println("-------breaht--------");
//org.apache.struts.action.ActionServlet
list = studentDao.getAll();
return "success";
}
}
前台页面代码:
<s:iterator value="list" var="index">
<!--<s:property value="name"/>-->
${index.name}
</s:iterator>