1.收藏和购物车图片 2.404页面无效 3.点购物车是404错误
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<filter>
<filter-name>CharsetEncodingFilter</filter-name>
<filter-class>com.imooc.cart.filter.CharsetEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharsetEncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ProductServlet</servlet-name>
<servlet-class>com.imooc.cart.servlet.ProductServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProductServlet</servlet-name>
<url-pattern>/product/List.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>CartServlet</servlet-name>
<servlet-class>com.imooc.cart.servlet.CartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CartServlet</servlet-name>
<url-pattern>/cart/list.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CartServlet</servlet-name>
<url-pattern>/cart/cart.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
</web-app>
package com.imooc.cart.servlet;
import com.imooc.cart.data.LocalCache;
import com.imooc.cart.data.Product;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
public class CartServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if(Objects.equals("/cart/cart.do",req.getServletPath())){
String productId=req.getParameter("productId");
if(null != productId){
Product product=LocalCache.getProduct(Long.valueOf(productId));
//把product的这个商品加入到购物车
LocalCache.addCart(product);
}
//需要跳转到购物车的页面
resp.sendRedirect("/cart/list.do");
}else if(Objects.equals("/cart/list.do",req.getServletPath())){
req.setAttribute("carts", LocalCache.getCarts());
req.getRequestDispatcher("/WEB-INF/views/biz/cart.jsp").forward(req,resp);
}
}
}
老师,因为那连个图标不正常显示,就改了下面代码让链接显示出来,之后再点就404了,
那两个图片在没写代码之前是正常显示的
<span>
<a href="/cart/cart.do?productId=${product.id}">
sdfsdf
</a>
</span>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星