servlet向jsp传值怎么是空的?
servlet的代码publicclassListAllStudentsServletextendsHttpServlet{privatestaticfinallongs...
servlet的代码
public class ListAllStudentsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
StudentDao studentDao=new StudentDao();
List<Student> students=studentDao.getAll();
request.setAttribute("students", students);
request.getRequestDispatcher("/students.jsp").forward(request, response);
}
JSP的代码:
<%
List<Student> stus = (List<Student>)request.getAttribute("students");
%>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>flowId</th>
<th>type</th>
<th>idCard</th>
<th>examCard</th>
<th>studentName</th>
<th>location</th>
<th>grade</th>
<th>DELETE</th>
</tr>
<%
for (Student student : stus) {
%>
<tr>
<td><%=student.getFlowId() %></td>
<td><%=student.getType() %></td>
<td><%=student.getIdCard() %></td>
<td><%=student.getExamCard() %></td>
<td><%=student.getStudentName() %></td>
<td><%=student.getLocation() %></td>
<td><%=student.getGrade() %></td>
<td><a href="deleteStudent?flowId=<%=student.getFlowId()%>">DELETE</td>
</tr>
<%
}
%>
</table>
补充在servlet中的students是有值的,从servlet向jsp中传固定的数也是可以的,就是传student的不行,求大神呀!小弟很急! 展开
public class ListAllStudentsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
StudentDao studentDao=new StudentDao();
List<Student> students=studentDao.getAll();
request.setAttribute("students", students);
request.getRequestDispatcher("/students.jsp").forward(request, response);
}
JSP的代码:
<%
List<Student> stus = (List<Student>)request.getAttribute("students");
%>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>flowId</th>
<th>type</th>
<th>idCard</th>
<th>examCard</th>
<th>studentName</th>
<th>location</th>
<th>grade</th>
<th>DELETE</th>
</tr>
<%
for (Student student : stus) {
%>
<tr>
<td><%=student.getFlowId() %></td>
<td><%=student.getType() %></td>
<td><%=student.getIdCard() %></td>
<td><%=student.getExamCard() %></td>
<td><%=student.getStudentName() %></td>
<td><%=student.getLocation() %></td>
<td><%=student.getGrade() %></td>
<td><a href="deleteStudent?flowId=<%=student.getFlowId()%>">DELETE</td>
</tr>
<%
}
%>
</table>
补充在servlet中的students是有值的,从servlet向jsp中传固定的数也是可以的,就是传student的不行,求大神呀!小弟很急! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询