$%7BpageContext.request.contextPath%7D路徑404的錯誤問題
阿新 • • 發佈:2021-01-09
問題描述:
在使用${pageContext.request.contextPath}時出現$%7BpageContext.request.contextPath%7D路徑404的錯誤
解決方案:
- 第一種情況:最常見也是最有可能發生的情況的解決方法:提升web.xml檔案中web-app標籤所包含的版本等級
修改
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
為
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
- 第二種情況:當你是想在ajax的url屬性處新增${pageContext.request.contextPath}時。
不能直接使用,應該在起始的jsp介面中加入
<input id="PageContext" type="text" value="${pageContext.request.contextPath}" hidden/>
然後通過
url: $("#PageContext").val()+'/xxx/xxx/xxx',
拼接的方式來解決。
- 第三種情況:當你在後臺需要使用到專案的資源路徑的話。就需要通過ajax的data向 後臺傳遞資料,且寫法為:
data:{pageContext:$("#PageContext").val()},