?? liststudent.java
字號(hào):
package com.stuman.service;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import com.stuman.dao.DAOFactory;
import com.stuman.dao.StudentDAO;
import com.stuman.domain.Student;
public class ListStudent {
private StudentDAO stuDao;
public StudentDAO getStudentDAO() {
return DAOFactory.getInstance().createStudentDAO();
}
// 異常還沒(méi)有處理
public void list(HttpServletRequest request, JspWriter out)
throws Exception {
String tmp = (String) request.getParameter("page");
if (tmp != null) {
listpage(request, out, Integer.parseInt(tmp));
} else {
listpage(request, out, 1);
}
}
public void listpage(HttpServletRequest request, JspWriter out, int page)
throws Exception {
String name = "", id = "", password = "", jiguan = "", dep = "", sex = "", tel = "", mail = "", mark = "";
stuDao = this.getStudentDAO();
List list = stuDao.getStudent();
if (list == null) {
out.print("尚無(wú)學(xué)生信息");
return;
}
int total = list.size();
int count = 0;
Iterator it = list.iterator();
Student stu;
// User user;
// OrderItem item;
// Flight flight;
while (count < (page - 1) * 5 && it.hasNext()) {
it.next();
count++;
}
count = 0;
while (it.hasNext() && count < 5) {
stu = (Student) it.next();
id = stu.getId();
name = stu.getName();
password = stu.getPassword();
jiguan = stu.getJiguan();
dep = stu.getDepartment();
sex = stu.getSex();
if( stu.getMark() != null )
mark = stu.getMark().toString();
tel = stu.getTel();
if (tel == null || tel.equals(""))
tel = "無(wú)";
mail = stu.getEmail();
if (mail == null || mail.equals(""))
mail = "無(wú)";
out.print("<tr><td>" + id + "</td><td>" + name + "</td><td>"
+ password + "</td><td>" + jiguan + "</td><td>" + dep
+ "</td><td>" + sex + "</td><td>" + mark + "</td><td>"
+ tel + "</td><td>" + mail + "</td>");
out.print("<td><a href=deleteStudent.do?student_id="
+ stu.getId() + ">刪除</a></td><td>");
out.print("<a href=updatestu.jsp?student_id="
+ stu.getId() + ">編輯</a></td></tr>");
count++;
}
out.print("<tr><td colspan=5 align=center>");
out.print("<table width=50% border=0 cellspacing=0><tr>");
if ((page - 1) > 0)
out
.print("<td width=50% colspan='5'> <a href=getStudent.jsp?page="
+ (page - 1) + ">上一頁(yè)</a> ");
else
out.print("<td width=50% colspan='5'>上一頁(yè)</td>");
if ((page - 1) < (total / 5))
out.print("<td width=50% colspan='5'><a href=getStudent.jsp?page="
+ (page + 1) + ">下一頁(yè)</a></td>");
else
out.print("<td width=50% colspan='5'>下一頁(yè)</td>");
out.print("</tr></table></td></tr>");
out.print("</table>");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -