首页 > 代码库 > filter原理
filter原理
index.jsp:
<a href="http://www.mamicode.com/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原理
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。