Skip to content

Instantly share code, notes, and snippets.

@shui
Created November 17, 2017 11:56
Show Gist options
  • Save shui/83c4e8cdb2a52bfcc94c9d6a842a7c38 to your computer and use it in GitHub Desktop.
Save shui/83c4e8cdb2a52bfcc94c9d6a842a7c38 to your computer and use it in GitHub Desktop.
JSP无法获取Model的值
    @RequestMapping(path = "/", method = GET)
    public String index(Model model)
            throws Exception {
        logger.info("processed by index");
        model.addAttribute("msg", "GOGOGO");
        return "go.jsp";
    }
<html>
<body>
${msg}
</body>
</html>

在页面中直接显式${msg}。参照http://blog.csdn.net/qq_24755999/article/details/72781275的解法:

JSP无法解析EL表达式。

两种解决办法:

  • 在JSP顶部加入isELIgnored="false"

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
    
  • 在web.xml的头部加入缺少的东西 Maven Archetype自动生成的如下

    <!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>
    

    替换成:

    <?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_4_0.xsd"  
          version="4.0">  
            
    </web-app>
    

    Ref:http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment