Servlet中路径问题:调度
Servlet中路径问题:调度
(1)调用后台方法
(2)根据结果完成跳转
重定向 response.sendRedirect(url);
转发 request.getRequestDispatcher(url).forward(request,response);
MyServlet: http://localhost/news/myServlet3
1 重定向 response.sendRedirect(url);
相对路径: response.sendRedirect("a/b.jsp");
http://localhost/news/a/b.jsp
绝对路径: response.sendRedirect("/a/b.jsp");
http://localhost/a/b.jsp
MyServlet: http://localhost/news/myServlet3
2 转发 request.getRequestDispatcher(url).forward(request,response);
相对路径: request.getRequestDispatcher("a/b.jsp").f..;
http://localhost/news/a/b.jsp
绝对路径: request.getRequestDispatcher("/a/b.jsp").f..;
http://localhost/news/a/b.jsp
实现新闻的修改和删除
(1)以前修改和删除处理页面(adminNewsDel.jsp doEdit.jsp)删掉不要,将代码剪切到两个Servlet中
(2)修改Servlet中跳转的路径
(3)页面提交地址由jsp-->Servlet
(<%=request.getContextPath%>/servlet/EditServlet)
过滤器:
(1)过滤所有 /*
(2)有针对性的过滤
针对http://localhost:8080/news/jsp/admin/*
http://localhost:8080/news/jsp/login.jsp
页面->user->session->admin/admin.jsp
Filter -->session中取user-->chain.doFilter()/error.jsp
<filter-name>TestFilter</filter-name>
<url-pattern>/jsp/admin/*</url-pattern>