首页 > 其他 > 详细

filter原理

时间:2017-03-22 21:19:40      阅读:96      评论:0      收藏:0      [点我收藏+]

index.jsp:

<a href="product-input.action">input</a>

<form action="product-save.action" method="post">
ProductName:<input type="text" name="productName"/><br>
productDesc:<input type="text" name="productDesc"/><br>
productPrice:<input type="text" name="productPrice"/><br>
<input type="submit" name="submit" value="submit">
</form>

details.jsp:

productId:${product.productId}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // TODO Auto-generated method stub
        // place your code here
        HttpServletRequest req=(HttpServletRequest) request;
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        String path = null;
        if("/product-input.action".equals(servletPath)){
            path="/WEB-INF/pages/input.jsp";
        }
        if("/product-save.action".equals(servletPath)){
            String productName = request.getParameter("productName");
            String productDesc = request.getParameter("productDesc");
            String productPrice = request.getParameter("productPrice");
            Product product = new Product(null, productName, productDesc, productPrice);
            product.setProductId(1001);
            System.out.println(product);
            request.setAttribute("product", product);
            path = "/WEB-INF/pages/details.jsp";
        }
        if(path!=null){
            request.getRequestDispatcher(path).forward(request, response);
            return;
        }
        // pass the request along the filter chain
        chain.doFilter(request, response);
    }

filterDispatcher

 

filter原理

原文:http://www.cnblogs.com/Nyan-Workflow-FC/p/6601865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!