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">//更新

JSP---一个Servlet处理多个请求操作,布布扣,bubuko.com

JSP---一个Servlet处理多个请求操作

上一篇:用 MySQL 存储 Emoji


下一篇:js函数调用二种常用方法的例子