jsp獲取url路徑的方法
如果你請求的URL是 http://localhost:8080/demo/Index.jsp
request.getScheme() //輸出:http
request.getServerName() //輸出: localhost
request.getServerPort() //輸出: 8080
request.getContextPath() //輸出: /demo
request.getRequestPath() //輸出: /Index.jsp
request.gerRequestURI() //輸出: /demo/Index.jsp
request.getRequestURL() //輸出: http://localhost:8080/demo/Index.jsp
request.getRealPath("") //輸出:D:\apache-tomcat-6.0.10\webapps\demo
jsp獲取url路徑的方法
如果你請求的URL是 http://localhost:8080/demo/Index.jsp
request.getScheme() //輸出:http
request.getServerName() //輸出: localhost
request.getServerPort() //輸出: 8080
request.getContextPath() //輸出: /demo
request.getRequestPath() //輸出: /Index.jsp
request.gerRequestURI() //輸出: /demo/Index.jsp
request.getRequestURL() //輸出: http://localhost:8080/demo/Index.jsp
request.getRealPath("") //輸出:D:\apache-tomcat-6.0.10\webapps\demo