java 获取 请求路径

获取此次请求的URL

String requestUrl = request.getScheme() //当前链接使用的协议
    +"://" + request.getServerName()//服务器地址 
    + ":" + request.getServerPort() //端口号 
    + request.getContextPath() //应用名称,如果应用名称为
    + request.getServletPath() //请求的相对url 
    + "?" + request.getQueryString(); //请求参数
http://127.0.0.1:8080/world/index.jsp?name=lilei&sex=1

request.getScheme() = "http";
request.getServerName() = "127.0.0.1";
request.getServerPort() = "8080";
request.getContextPath() = "world";
request.getServletPath() = "index.jsp

你可能感兴趣的:(Java)