JSP&&SERVLET学习笔记(三):URL模式设置

//URL模式的设置
//                         环境路径          Servlet路径    路径信息
//requestURI = contextPath + servletPath + pathInfo;
//Servlet路径认为/*为空串


package cc.openhome;


import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/servlet/*")
public class PathServlet extends HttpServlet {
  
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Pattern</title>");
out.println("</head>");
out.println("<body>");
out.println(request.getRequestURI() + "<br>");
out.println(request.getContextPath() + "<br>");
out.println(request.getServletPath() + "<br>");
out.println(request.getPathInfo());
out.println("</body>");
out.println("</html>");
out.close();
}


}

你可能感兴趣的:(JSP&&SERVLET学习笔记(三):URL模式设置)