jsp 中的路徑
一些小盆友總是詢 jsp 的一些路徑到底指的是啥 今天就來扒拉一下
比如我在jsp中寫了一段Java代碼 :

一:獲取路徑:訪問路徑
jsp中訪問后臺需要url,一般不會把url寫死,會使用代碼來獲取基本路徑,以便以后的修改。
1.path = request.getContextPath(); :-------/webName 項目名稱
2.request.getScheme() :協議名字 ----------------http
3.request.getServerName():服務器名字 -------localhost
4.request.getServerPort():端口號------8080
5.request.getServletPath(),返回當前頁面所在目錄下全名稱:/course/index.jsp;
6.request.getRequestURL(),返回IE地址欄地址:http://localhost:8080/WebName/course/index.jsp;
7.request.getRequestURI() ,返回包含工程名的當前頁面全路徑:/webName/course/index.jsp
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
http://localhost:8080/WebName/
舉例
String path = request.getContextPath(); ------------ /course
request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/" ----http://localhost:8080/course/
---------------------
個性 簽名:真正的學習不是記住知識,而是學會如何提出問題,研究問題,解決問題。
如果覺得這篇文章對你有小小的幫助的話,記得在下方“關注”哦,博主在此感謝!

浙公網安備 33010602011771號
返回頂部