本文實(shí)例講述了jsp獲取url路徑的方法。分享給大家供大家參考,具體如下:
如果你請(qǐng)求的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
上面幾個(gè)我都驗(yàn)證過了,除了request.getRequestPath() 無(wú)法使用外(估計(jì)這個(gè)函數(shù)已經(jīng)被廢棄掉了吧),其它的顯示都正確。
希望本文所述對(duì)大家JSP程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選