getPathInfo() getServletPath() getContextPath() getRequestURL() getRequestURI()
来源:互联网 发布:阿里云病毒入侵 编辑:程序博客网 时间:2024/06/10 20:30
day117为项目名
1.在servlet中访问
(一) web.xml
<servlet> <servlet-name>Aservlet</servlet-name> <servlet-class>day117.Aservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Aservlet</servlet-name> <url-pattern>/test/*</url-pattern> </servlet-mapping>
(二) servlet
package day117;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class Aservlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();String pathInfo = request.getPathInfo();System.out.println("pathInfo:"+pathInfo);String servletPath = request.getServletPath();System.out.println("servletPath:"+servletPath);String contextPath = request.getContextPath();System.out.println("contextPath:"+contextPath);StringBuffer requestURL = request.getRequestURL();System.out.println("requestURL:"+requestURL);String requestURI = request.getRequestURI();System.out.println("requestURi:"+requestURI);}public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet(request, response);}}
(三) 运行结果
访问 http://localhost/day117/test/hello/world?name=jack
pathInfo:/hello/world
servletPath:/test
contextPath:/day117
requestURL:http://localhost/day117/test/hello/world
requestURi:/day117/test/hello/world
servletPath:/test
contextPath:/day117
requestURL:http://localhost/day117/test/hello/world
requestURi:/day117/test/hello/world
2.在jsp中访问
path.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% String pathInfo = request.getPathInfo();System.out.println("pathInfo:"+pathInfo);String servletPath = request.getServletPath();System.out.println("servletPath:"+servletPath);String contextPath = request.getContextPath();System.out.println("contextPath:"+contextPath);StringBuffer requestURL = request.getRequestURL();System.out.println("requestURL:"+requestURL);String requestURI = request.getRequestURI();System.out.println("requestURi:"+requestURI); %> </body></html>
(三) 运行结果
访问 http://localhost/day117/path.jsp?name=jack
pathInfo:null
servletPath:/path.jsp
contextPath:/day117
requestURL:http://localhost/day117/path.jsp
requestURi:/day117/path.jsp
servletPath:/path.jsp
contextPath:/day117
requestURL:http://localhost/day117/path.jsp
requestURi:/day117/path.jsp
阅读全文
0 0
- getPathInfo() getServletPath() getContextPath() getRequestURL() getRequestURI()
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()、getPathInfo()
- request.getContextPath().getRequestURI().getServletPath().getRequestURL().getRealPath() 图解
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、的区别
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- request.getRequestURI() 、request.getRequestURL() 、request.getContextPath()、request.getServletPath()区
- getRequestURL、getRequestURI、getContextPath、getServletPath和getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的区别
- JavaWEB中request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- HttpServletRequest getServletPath() getContextPath() getRequestURI()
- getContextPath getServletPath getRequestURI
- 快速排序算法
- 概要设计与详细设计的区别(转)
- JFreeChart中的时序图
- Dubbo基本原理机制
- Vector3
- getPathInfo() getServletPath() getContextPath() getRequestURL() getRequestURI()
- Linux服务器管理
- 1+2+3+4+……+n的和
- iOS 开发之环形倒计时进度条(虚线/实线)
- 百度闪电算法什么时间开始
- Vue修改mint-ui默认样式
- 共享电吹风方案开发
- 【JVM】10_长期存活的对象将进入老年代
- vue debug