spring-mvc解决EL表达式不能使用问题

刚开始学习spring mvc时经常会遇到 的一个问题就是在Controller层使用ModelAndView的addObject方法保存数据后,在jsp页面中使用EL表达式进行获取得不到数据,而是直接显示表达式的值,如${message},产生这个问题的原因主要是JSP1.2默认的EL表达式是关闭的,而JSP2.0默认的EL表达式是打开的。

      解决方法为: 

      1)、采用JSP1.2 

             web.xml配置信息为

[html]  view plain  copy
  1. <!DOCTYPE web-app PUBLIC  
  2.  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  
  3.  "http://java.sun.com/dtd/web-app_2_3.dtd" >  
  4.    
  5. <web-app>  
  6.   
  7. </web-app>  
EL是关闭的,必须手动打开。<%@page isELIgnored="false" %>

      2)、采用JSP2.0

            web.xml的配置信息为     

[html]  view plain  copy
  1. <web-app id="WebApp_ID" version="2.4"   
  2. xmlns="http://java.sun.com/xml/ns/j2ee"   
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
  5. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  6. //...  
  7. </web-app>  
      可以直接使用。

      以下配置为成功的示例:

      web.xml文件       

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.     xmlns="http://java.sun.com/xml/ns/javaee"   
  4.     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
  6.     id="WebApp_ID" version="2.5">  
  7.   
  8. </web-app>  
       jsp页面       

[html]  view plain  copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  7. <title>Hello World</title>  
  8. </head>  
  9. <body>  
  10.     ${message}  
  11. </body>  
  12. </html>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值