为什么在JSP文件中没有EL解释?

时间:2015-08-03 22:43:42

标签: java jsp java-ee el

环境:

  • Tomacat 8
  • Servlet 3.1
  • JSP 2.3
  • Java 1.7.0_79
  • 的Maven
  • Struts2的

为什么不在这个JSP文件中使用EL?

el.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    ${5+3 }
    ${5+hola }
    <s:url action="registerInput" var="registerInputLink" />
    ${registerInputLink}
</body>
</html>

我在网页上看到的是:

${5+3 } ${5+hola }  ${registerInputLink} 

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

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

1 个答案:

答案 0 :(得分:0)

问题似乎与您的web.xml有关。您必须向web-app标记添加一些名称空间

servlet 3.1的web.xml标题

<?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_3_1.xsd"
    version="3.1">
    <!-- Config here -->

您可以在Tomcat安装附带的示例应用程序中找到Tomcat实例的正确名称空间。