在index.jsp中有兩個(gè)路徑,一個(gè)是path,一個(gè)是basePath,我用response.sendRedirect(path+"/users/Users_login.jsp");可以正常運(yùn)行,用response.sendRedirect(basePath+"/users/Users_login.jsp");也能正常運(yùn)行,那請(qǐng)問(wèn):都能運(yùn)行正常,要一個(gè)就行了,那這個(gè)basePath有什么用?如下圖:
我發(fā)現(xiàn)這節(jié)課給的素材里邊的所有jsp頁(yè)面內(nèi)容里根本沒(méi)用basePath。那就奇怪了,既然沒(méi)用basePath,那在這里寫(xiě)這個(gè)String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";有什么用?
2016-06-21
<%
? ?String path = request.getContextPath();
? ?String basePath = request.getScheme() + "://"
? ? ? ? ? ?+ request.getServerName() + ":" + request.getServerPort()
? ? ? ? ? ?+ path + "/";
%>
basePath 這里指的是你項(xiàng)目的絕對(duì)路徑,就是你的地址欄信息(如:http://localhost:8080/Test/test)。如果沒(méi)有basePath 的話,會(huì)以你提交的次數(shù)你的地址會(huì)變成(如:http://localhost:8080/Test/Test/Test/test),導(dǎo)致出現(xiàn)報(bào)錯(cuò)404。