fix<路径调整>
parent
91491824ec
commit
cd1fd254d7
|
|
@ -65,7 +65,7 @@ public class CartServlet extends HttpServlet {
|
|||
User user = (User) req.getSession().getAttribute("user");
|
||||
cartService.addCart(Integer.parseInt(id),user.getId());
|
||||
req.setAttribute("msg","加购成功");
|
||||
req.getRequestDispatcher("/computerList").forward(req,resp);
|
||||
req.getRequestDispatcher("/computer?action=list").forward(req,resp);
|
||||
}
|
||||
|
||||
private void toCart(HttpServletRequest req, HttpServletResponse resp) throws Exception {
|
||||
|
|
|
|||
|
|
@ -10,32 +10,33 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
@WebServlet(urlPatterns = {"/computerList","/deleteComputer","/addComputer","/editComputer"})
|
||||
@WebServlet(urlPatterns = {"/computer"})
|
||||
public class ComputerServlet extends HttpServlet {
|
||||
|
||||
IComputerService computerService = new ComputerServiceImpl();
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String path = req.getServletPath();
|
||||
switch (path) {
|
||||
case "/computerList":
|
||||
String action = req.getParameter("action");
|
||||
switch (action) {
|
||||
case "list":
|
||||
try {
|
||||
listServlet(req, resp);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
case "/deleteComputer":
|
||||
case "delete":
|
||||
deleteComputer(req, resp);
|
||||
break;
|
||||
case "/addComputer":
|
||||
case "add":
|
||||
addComputer(req, resp);
|
||||
break;
|
||||
case "/editComputer":
|
||||
case "edit":
|
||||
editComputer(req, resp);
|
||||
break;
|
||||
}
|
||||
|
|
@ -56,7 +57,7 @@ public class ComputerServlet extends HttpServlet {
|
|||
String id = req.getParameter("id");
|
||||
try {
|
||||
computerService.deleteComputer(id);
|
||||
resp.sendRedirect("/computerList");
|
||||
resp.sendRedirect("/computer?action=list");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -70,25 +71,25 @@ public class ComputerServlet extends HttpServlet {
|
|||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String path = req.getServletPath();
|
||||
switch (path) {
|
||||
case "/addComputer":
|
||||
String action = req.getParameter("action");
|
||||
switch (action) {
|
||||
case "add":
|
||||
savaComputer(req, resp);
|
||||
break;
|
||||
case "/editComputer":
|
||||
UpdatComputer(req, resp);
|
||||
case "edit":
|
||||
UpdateComputer(req, resp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatComputer(HttpServletRequest req, HttpServletResponse resp) {
|
||||
private void UpdateComputer(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
|
||||
String id = req.getParameter("id");
|
||||
String name = req.getParameter("name");
|
||||
String price = req.getParameter("price");
|
||||
String stock = req.getParameter("stock");
|
||||
computerService.updateComputer(id,name,Double.parseDouble(price),Integer.parseInt(stock));
|
||||
try {
|
||||
resp.sendRedirect("/computerList");
|
||||
resp.sendRedirect("/computer?action=list");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -100,7 +101,7 @@ public class ComputerServlet extends HttpServlet {
|
|||
String stock = req.getParameter("stock");
|
||||
computerService.addComputer(name,Double.parseDouble(price),Integer.parseInt(stock));
|
||||
try {
|
||||
resp.sendRedirect("/computerList");
|
||||
resp.sendRedirect("/computer?action=list");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>电脑产品发布</h1>
|
||||
<form action="/addComputer" method="post">
|
||||
<form action="/computer?action=add" method="post">
|
||||
<label for="name">名称: </label><br>
|
||||
<input type="text" id="name" name="name"><br><br>
|
||||
<label for="price">价格: </label><br>
|
||||
|
|
@ -19,6 +19,6 @@
|
|||
<input type="submit" value="确定">
|
||||
</form>
|
||||
<br>
|
||||
<a href="/computerList">返回电脑列表</a>
|
||||
<a href="/computer?action=list">返回电脑列表</a>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
<td>${computer.stock}</td>
|
||||
<td>
|
||||
<c:if test="${sessionScope.user.role == 'admin'}">
|
||||
<a href="/editComputer?id=${computer.id}">编辑</a> |
|
||||
<a href="/deleteComputer?id=${computer.id}">删除</a>
|
||||
<a href="/computer?action=edit&id=${computer.id}">编辑</a> |
|
||||
<a href="/computer?action=delete&id=${computer.id}">删除</a>
|
||||
</c:if>
|
||||
|
||||
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
<a href="/cart?action=list">我的购物车</a>
|
||||
</c:if>
|
||||
<c:if test="${sessionScope.user.role == 'admin'}">
|
||||
<a href="/addComputer">发布电脑产品</a>
|
||||
<a href="/computer?action=add">发布电脑产品</a>
|
||||
</c:if>
|
||||
<br>
|
||||
<a href="/">主页</a>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>更新电脑信息</h1>
|
||||
<form action="/editComputer" method="post">
|
||||
<form action="/computer?action=edit" method="post">
|
||||
<input type="hidden" name="id" value="${computer.id}">
|
||||
<label for="name">名称: </label><br>
|
||||
<input type="text" id="name" name="name" value="${computer.name}"><br><br>
|
||||
|
|
@ -21,6 +21,6 @@
|
|||
<input type="submit" value="提交修改">
|
||||
</form>
|
||||
<br>
|
||||
<a href="/computerList">返回电脑列表</a>
|
||||
<a href="/computer?action=list">返回电脑列表</a>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<h2>电脑商城-首页</h2>
|
||||
<p>你好!${sessionScope.user.username}</p>
|
||||
<c:if test="${sessionScope.user!= null}">
|
||||
<a href="/computerList">电脑选购</a>
|
||||
<a href="/computer?action=list">电脑选购</a>
|
||||
<c:if test="${sessionScope.user.role == 'user'}">
|
||||
<a href="/cart?action=list">我的购物车</a>
|
||||
<a href="/orders?action=my">我的订单</a>
|
||||
|
|
|
|||
Reference in New Issue