jsp页面无法识别el表达式的解决方案

原文链接: http://www.cnblogs.com/fingerboy/p/6007040.html

  今天在写一个springmvc的小demo时,碰到一个问题,在jsp页面中书写为${user.username}的表达式语言,在浏览器页面中仍然显示为${user.username},说明jsp根本不认识${}标签,摸索了一下,发现我的web.xml中声明的是

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

  这表示的是servlet使用的2.3版本,查了一下,默认情况下,Servlet2.3/jsp1.2默认是不支持el表达式的,此时有两种解决方案,测试都能解决问题.

  第一种方式,是直接在jsp文件头部标签前加入

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

  表示强制性的不忽略el表达式格式,重新测试,成功显示数据.

  第二种方式就是使用servlet的更高版本,比如我直接将web.xml改成2.5版本:

<?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"
         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">

</web-app>

  此时,不需要设置 isELIgnored="false" 因为此版本已经默认支持el表达式了.

转载于:https://www.cnblogs.com/fingerboy/p/6007040.html

猜你喜欢

转载自blog.csdn.net/weixin_30294709/article/details/94790556