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); } }