本文實例講述了jsp獲取url路徑的方法。分享給大家供大家參考,具體如下:
如果你請求的URL是 http://localhost:8080/demo/Index.jsp
request.getScheme() //輸出:httprequest.getServerName() //輸出: localhostrequest.getServerPort() //輸出: 8080request.getContextPath() //輸出: /demorequest.getRequestPath() //輸出: /Index.jsprequest.gerRequestURI() //輸出: /demo/Index.jsprequest.getRequestURL() //輸出: http://localhost:8080/demo/Index.jsprequest.getRealPath("") //輸出:D:/apache-tomcat-6.0.10/webapps/demo
上面幾個我都驗證過了,除了request.getRequestPath() 無法使用外(估計這個函數已經被廢棄掉了吧),其它的顯示都正確。
希望本文所述對大家JSP程序設計有所幫助。
新聞熱點
疑難解答