在主页里添加注册,删除,和修改超链接
先在页面导入jstl的核心类库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>成功</title>
</head>
<h3>欢迎${user.username}来到主页</h3>
<table>
<tr>
<th><a href="addGoods.jsp">添加商品</a></th>
</tr>
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>商品价格</th>
<th>商品说明</th>
<th>操作</th>
</tr>
<c:forEach items="${goodsList}" var="goods">
<tr>
<td>${goods.gid}</td>
<td>${goods.gname}</td>
<td>${goods.price}</td>
<td>${goods.mark}</td>
<td><a href="upd?gid=${goods.gid}">修改</a></td>
<td><a href="del?gid=${goods.gid}">删除</a></td>
</tr>
</c:forEach>
点击商品添加来到商品添加页面
<html>
<head>
<title>商品添加</title>
</head>
<body>
<form action="addGoods" content="post">
商品名称:<input type="text" name="gname" value=""><br/>
商品价格:<input type="number" step="0.01" name="price" value=""><br/>
商品介绍:<input type="text" name="mark" value=""><br/>
<input type="submit" name="" value="确定">
</form>
</body>
</html>
使用Servlet编写添加商品
@WebServlet("/addGoods")
public class AddGoods extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置编码格式
request.setCharacterEncoding("utf-8");//请求编码
response.setCharacterEncoding("utf-8");//响应编码
// resp.setContentType("text/html;charset=UTF-8");
//获取请求的参数
Goods goods=new Goods();
goods.setGname(request.getParameter("gname"));
good