JSP---一个Servlet处理多个请求操作
1、Servlet
public void excute(HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("utf-8");
String operate = request.getParameter("operate");
if (operate == null || operate.equals("")) {
operate = "list";
}
if (operate.equals("save")) {
save(request, response);
} else if (operate.equals("edit")) {
edit(request, response);
} else if (operate.equals("update")) {
update(request, response);
} else if (operate.equals("delete")) {
delete(request, response);
}
}
public void list(HttpServletRequest request, HttpServletResponse response){//todo}
public void save(HttpServletRequest request, HttpServletResponse response){//todo}
public void edit(HttpServletRequest request, HttpServletResponse response){//todo}
public void update(HttpServletRequest request, HttpServletResponse response){//todo}
public void delete(HttpServletRequest request, HttpServletResponse response){//todo}
2.jsp
<form name="formAdd" action="pet.do?operate=save" method="post">//增
<a href="pet.do?operate=edit&id=${pet.pet_id}">修改</a> //改
<a href="pet.do?operate=delete&id=${pet.pet_id}">删除</a> //删
<form name="formEdit" action="pet.do?operate=update" method="post">//更新
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。