1. 程式人生 > >【坑】關於使用 maven 建立 web 專案以後,el 表示式不被識別的解決方法

【坑】關於使用 maven 建立 web 專案以後,el 表示式不被識別的解決方法


問題描述:

在學習 Ajax 的時候,使用資源路徑,博主本著不要硬編碼,局使用 el 表示式進行讀取專案名,然後發現 el 表示式沒有被識別,而是當做字串 ${pageContext.request.contextPath} 直接輸出了,很是鬱悶啊;

突然想起來沒加 jar 包,在 pom 檔案裡面一通配置,還是不行,然後各種匯入相關的 jar 包,IDEA 穩如泰山的給我按照字串輸出;


解決方法:

在確保你相關的 jar 包都匯入了,就開啟你專案的 web.xml 看下,看下 maven 給建立的是哪一個版本的 web 專案;

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app> <display-name>Archetype Created Web Application</display-name> </web-app>

我的開啟,竟然是 2.3 ,這不扯犢子一樣,el 表示式在低版本中是不被識別的,趕緊開啟以前的專案,複製一份 web.xml 的眉頭 ;

<?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_3_1.xsd" version="3.1">

然後,就 OK 了 ;


從今天起,我要記錄下我踩過的坑,本來學 Ajax,結果時間全用在除錯 el 表示式上了。–2018年12月6日17:55:32