项目在spring boot自带的Tomcat本地环境中测试都没问题,但是打包部署到测试环境中后有的El表达式失效,但是有的El表达式解析正常,在获取工程名称中<link href="${pageContext.servletContext.contextPath }/wx/css/my.css" rel="stylesheet" type="text/css" />中{}被解析成字符串
但是有的css和js资源解析却是正常的,所以后很纳闷。查资料得知: 使用spring boot创建的web app在2.5之后在jsp中isELIgnored
默认是true.会自动忽略el表达式。
解决方案一:
在jsp中直接添加
<%@ page isELIgnored="false" %>
这样的话,如果有大量的jsp需要修改会比较麻烦,所以不太推荐使用。
解决方案二:
在web.xml文件中修改
<?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">
<jsp-config>
<jsp-property-group>
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>
</web-app>
这样就可以了完全解决问题。