JSP页面EL表达式不解析

您所在的位置:网站首页 el表达式解析 JSP页面EL表达式不解析

JSP页面EL表达式不解析

2023-09-18 00:44| 来源: 网络整理| 查看: 265

问题是这样:在搭建springMVC环境的时候,笔者写了一个简单的Controller如下:

@Controller public class HelloController { @RequestMapping(value = "/hello.do", method = RequestMethod.GET) public String hello(Model model) { model.addAttribute("hello", "hello_SpringMVC"); model.addAttribute("message", "Hello SpringMVC"); return "hello"; } }

调用这个控制器,返回hello.jsp,页面代码如下:

DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> Insert title here ${hello} ${message} ${hello123 }

正常情况下页面应该会输出字符串信息,可是实际上输出结果是未经解析的EL表达式。

image

笔者查看了日志,发现hello和message都正确的转发到了hello.jsp中,可是EL表达式为什么没有正确的解析呢?

image

经过查阅资料,有四种情况下EL表达式是无法正确别解析的,

分别是:

Application server in question doesn't support JSP 2.0. (应用服务器不支持JSP2.0) The web.xml is not declared as Servlet 2.4 or higher.  (web.xml中servlet版本没有声明在2.4以上) The @page is configured with isELIgnored=true. (页面上配置了 ) The web.xml is configured with true in . (web.xml中显式地配置了忽略EL表达式)

最终发现我的web.xml中声明的servlet版本是2.3,所以默认是不自动解析EL表达式的。

而我的web.xml这样是使用了maven-archetype-webapp创建的缘故。

DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > Archetype Created Web Application springmvc org.springframework.web.servlet.DispatcherServlet 1 springmvc *.do

只要更改成如下即可, 版本最好是你项目中使用的JSP版本,

...

 

总结一下:页面无法解析EL表达式是因为web.xml中JSP版本在2.4一下,而我在项目中使用的是JSP3.0,原因在于工程是通过maven-archetype-webapp创建的,而这个maven工程默认还在使用JDK1.5。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3