form action="/actionServlet.do"
<a href="/menu.html">菜單</a>
前面加斜杠 / ,是跳轉(zhuǎn)到整個(gè)網(wǎng)站的根目錄,即http://localhost:8080/,即ip:port,這是不包括項(xiàng)目名的。
所以一般在jsp頁(yè)面寫路徑是這樣,url="${pageContext.request.contextPath}/xxx"
跳轉(zhuǎn)
request.getRequestDispatcher("/test/search.jsp"),跳轉(zhuǎn)的路徑前面加斜杠,是跳轉(zhuǎn)到項(xiàng)目名后面,即http://localhost:8080/項(xiàng)目名/
重定向
response.sendRedirect(contextPath+"/test/search.jsp");重定向的原理和html一樣,加斜杠/會(huì)直接前往根目錄后,即不帶項(xiàng)目名。所以需要獲取getContextPath()
聯(lián)系客服