java web 相對路徑中已/開頭和不已/開頭的區別,javaweb

來源:互聯網
上載者:User

java web 相對路徑中已/開頭和不已/開頭的區別,javaweb
通俗的講,有/會從跟目錄開始算,沒有會從目前的目錄開始算1.前台頁面

頁面中向伺服器頁面請求靜態資源且沒有指定<base href="<%=basePath%>">

訪問以下頁面

localhost:8080/resolvent/index.jsp

localhost:8080/resolvent/servlet/dnf

有/的

跟目錄是網域名稱+連接埠號碼(localhost:8080)

請求以下資源

<script type="text/css" src=''/demo.js"></script>

最終瀏覽器發送的請求都是localhost:8080/demo.js

沒有/

<script type="text/css" src=''demo.js"></script>

localhost:8080/resolvent/demo.js  目前的目錄localhost:8080/resolvent/

localhost:8080/resolvent/servlet/demo.js 目前的目錄 localhost:8080/resolvent/servlet/

2.後台代碼

請求轉寄,請求重新導向,已以下兩個url為例

localhost:8080/resolvent/servlet/dnf

localhost:8080/resolvent/index.jsp

有/的

根目錄是(localhost:8080/resolvent)

request.getRequestDispatcher("/login.jsp").forward(request,response);

最後都會定位到

localhost:8080/resolvent/login.jsp

沒有/

request.getRequestDispatcher("login.jsp").forward(request,response);

localhost:8080/resolvent/servlet/login.jsp  目前的目錄localhost:8080/resolvent/servlet/

localhost:8080/resolvent/login.jsp  目前的目錄localhost:8080/resolvent/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.