package cn.meeting.core;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 执行转发用的
*
*1 区别html
假定你的web application 名称为qlumeeting,你在浏览器中输入请求路径:java
http://localhost/qlumeeting/login.htmlweb
1.1 System.out.println(request.getContextPath());浏览器
打印结果:/qlumeetingapp
1.2 System.out.println(request.getServletPath());webapp
打印结果:/login.htmlspa
1.3 System.out.println(request.getRequestURI());htm
打印结果:/qlumeeting/login.htmlget
1.4 System.out.println(request.getRealPath("/"));servlet
打印结果:F:\Tomcat 6.0\webapps\news\test
*
*/
public class ForwardServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String contextPath = request.getContextPath();// /qlumeeting String uri = request.getRequestURI();// /qlumeeting/login.html uri = uri.replace(contextPath,"");// /login.html String path = "/WEB-INF"+uri;// /WEB-INF/login.html System.err.println(path); request.getRequestDispatcher(path).forward(request, response); } }