JSTL_改写MVC案例
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function() {
$(".delete").click(function name() {
var content = $(this).parent().parent().find("td:eq(1)").text();
var flag = confirm("确定要删除" + content + "的信息吗?");
return flag;
});
});
</script>
</head>
<body>
<form action="query.do"
method="post">
<table>
<tr>
<td>name:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>address:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>phone:</td>
<td><input type="text" name="phone" /></td>
</tr>
<tr>
<td><input type="submit" value="Query" /></td>
<td><a href="newcustomer.jsp">Add New Customer</a></td>
</tr>
</table>
</form>
<hr>
<br>
<br>
<c:if test="${!empty requestScope.customers }">
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>Id</th>
<th>CustomerName</th>
<th>Address</th>
<th>Phone</th>
<th>UPDATE</th>
<th>DELETE</th>
</tr>
<c:forEach items="${requestScope.customers }" var="customer">
<tr>
<td>${customer.id }</td>
<td>${customer.name }</td>
<td>${customer.address }</td>
<td>${customer.phone }</td>
<td>
<c:url value="/edit.do" var="editurl">
<c:param name="id" value="${customer.id }"></c:param>
</c:url>
<a href="${editurl }">Edit</a>
</td>
<td>
<c:url value="/delete.do" var="deleteurl">
<c:param name="id" value="${customer.id }"></c:param>
</c:url>
<a class="delete" href="${deleteurl }">Delete</a>
</td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:if test="${requestScope.message != null }">
<br>
<font color="red">${requestScope.message }</font>
<br>
</c:if>
<form action="add.do" method="post">
<table>
<tr>
<td>name:</td>
<td><input id="name" type="text" name="name" value="${param.name }" /></td>
</tr>
<tr>
<td>address:</td>
<td><input id="address" type="text" name="address" value="${param.address }" /></td>
</tr>
<tr>
<td>phone:</td>
<td><input id="phone" type="text" name="phone" value="${param.phone }" /></td>
</tr>
<tr>
<td colspan="2"><input id="add" type="submit" value="Add" /></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:if test="${requestScope.message != null }">
<br>
<font color="red">${requestScope.message }</font>
<br>
</c:if>
<c:set var="id" value="${customer != null ? customer.id : param.id }"></c:set>
<c:set var="oldName" value="${customer != null ? customer.name : param.oldName }"></c:set>
<c:set var="newName" value="${customer != null ? customer.name : param.oldName }"></c:set>
<c:set var="newAddress" value="${customer != null ? customer.address : param.newAddress }"></c:set>
<c:set var="newPhone" value="${customer != null ? customer.phone : param.newPhone }"></c:set>
<form action="update.do" method="post">
<input name="id" type="hidden" value="${id }" />
<input name="oldName" type="hidden" value="${oldName }" />
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<td>CustomerName</td>
<td><input name="newName" type="text"
value="${newName }" /></td>
</tr>
<tr>
<td>Address</td>
<td><input name="newAddress" type="text"
value="${newAddress }" /></td>
</tr>
<tr>
<td>Phone</td>
<td><input name="newPhone" type="text"
value="${newPhone }" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Update" /></td>
</tr>
</table>
</form>
</body>
</html>