低压槽 2019-05-12 14:18 采纳率: 0%
浏览 344
已结题

TomCat控制器转发jsp页面404

1.通过filter过滤器作为控制器转发页面失败。

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //1.获取servletPath
        HttpServletRequest req=(HttpServletRequest) request;
        String servletPath=req.getServletPath();
        System.out.println(servletPath);
        String path=null;
        //2.判断servletPath,若其等于"/product-input.action",则转发到
        //WEB-INF/pages/input.jsp
        if("/product-input.action".equals(servletPath)) {
            path="/WEB-INF/pages/input.jsp";
        }
        if(path!=null) {
            request.getRequestDispatcher(path).forward(request, response);
            return;
        }
        //3.若其等于"/product-save.action"则
        if("/product-save.action".equals(servletPath)) {
            //1).获取请求参数
            String productName=request.getParameter("productName");
            String productDesc=request.getParameter("productDesc");
            String productPrice=request.getParameter("productPrice");
            //2).把请求信息封装为一个Product对象
            Product product=new Product(null, productName, productDesc, Double.parseDouble(productPrice));
            //3).执行保存操作
            System.out.println("SavaProduct:"+product);
            product.setProductId(1001);
            //4).把Product对象保存到request中。
            request.setAttribute("product", product);
            path="/WEB-INF/pages/details.jsp";
        }
        chain.doFilter(request, response);
    }

以下是details.jsp页面完整代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    ProductID:${requestScope.product.productId}
    <br><br>
    ProductName:${requestScope.product.productName}
    <br><br> 
    ProductDesc:${requestScope.product.productDesc}
    <br><br> 
    ProductPrice:${requestScope.product.productPrice}
    <br><br>  
</body>
</html>

图片说明
Tomcat404错误。求大神解答。

  • 写回答

3条回答

  • 「已注销」 2019-05-12 14:26
    关注

    看你配置tomcat的名字对不对 ,是不是中文

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用