Used to resolve Request.setattribute in action ("list", list)
Since I'm using the struts framework, I'll take the whole project:
1. First load the Jstl two common package Jstl.jar, Standard.jar into the environment
2.Action Code: (The whole process does not need to understand, here method is to return a Package students object list, and then Request.setattribute ("list", list) up)
public ActionForward selectStudent(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;
DBConnection dbconn = new DBConnection();
Connection conn = dbconn.getConnection();
StudentServiceFactory serviceFactory = new StudentServiceFactory();
List list = serviceFactory.getStudentService().selectStudent(conn);
request.setAttribute("list",list);
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return mapping.findForward("show");
}
3.show.jsp page:
<%@ page language= "java" pageencoding= "Utf-8"%>
<%@ taglib uri= "Http://java.sun.com/jstl/core_" RT "Prefix=" C "%>//these three are important.
<%@ taglib uri=" Http://jakarta.apache.org/struts/tags-bean "prefix=" Bean "%>
<%@ taglib uri= "/web-inf/struts-logic.tld" prefix= "logic"%>
<%
String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
<base href= "<%=basePath%>"
<title>my JSP ' show.jsp ' starting page</title>
<meta http- equiv= "Pragma" content= "No-cache"
<meta http-equiv= "Cache-control" content= "No-cache"
<meta http-equiv= "Expires" content= "0" >
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" conTent= the "This are my page"
<!--
<link rel= "stylesheet" type= "Text/css" href= "Styles.css"
-->
<body>
The
Query results are as follows: <br>
<table>
<tr>
<td>id</td>
<td> name </td>
</t R>
<c:foreach items= "${list}" var= "Student" >//items are an iterator for the list, which is the list that passes through the action. Student for Student class object
<tr>
<td>${student.id}</td>//output Student id attribute
<td>${stu Dent.name}</td>//output Student The Name property
</tr>
</c:foreach>
<logic:iterate id= "li" name = "List" type= "Vo". Student ">//id for the custom name, the List,type that is passed in the action is the entity class, including the full path, which is VO. Student
<tr>
<td><bean:write name= "li" property= "id"/></td>//name as the logical name, and Logic:it The ID in the erate id= "Li" corresponds to the real property of the entity class
<td><bean:write name= "li" property= "name"/></TD>
<td><a href= "Student.do?method=deletestudent&id=<bean:write name=" li "property=" id "/>" > Delete </a></td>
</tr>
</logic:iterate>
</tAble>
<a href= "student.jsp" > Return </a>
</body>
The JSP page introduces a struts tag library differently:
The struts1.3 are as follows:
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>或者<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>