未在jsp中计算el表达式

uinbv5nw  于 2021-10-10  发布在  Java
关注(0)|答案(5)|浏览(272)

我的servlets/jsp web应用程序有一个小问题。我试图在jsp页面中使用jstl。例如,当我使用任何标记时:

<c:out value="${command}"/>

它告诉我

${command}

在我的浏览器中,而不是参数“命令”值。我正在使用maven(我想问题就在这里)。以下是pom xml依赖项:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

my web.xml声明标记:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

和jsp部分:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
<title>Parsing results</title>
<link type="text/css" rel="stylesheet" href="css/page.css"/>
<link type="text/css" rel="stylesheet" href="css/table.css"/>
</head>

<body>
<h2 align="center">Results of 
parsing. Parsing method = <c:out value="${command}"/></h2>.......

编辑:设置命令值的代码很简单:

request.setAttribute("command", parser.getName());

然后去

request.getRequestDispatcher(redir).forward(request, response);

请告诉我,我做错了什么!谢谢!

3ks5zfa0

3ks5zfa01#

是的,我在web.xml中有doctype <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd"; > 去掉那个 <!DOCTYPE> 从…起 web.xml 并确保 <web-app> 声明为符合servlet 2.4或更新版本,所有这些都应该是良好的。
与Servlet3.0(Tomcat7、JBossAS6-7、GlassFish3等)兼容的有效servlet web.xml 整体如下所示,没有任何 <!DOCTYPE> :

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <!-- Config here. -->

</web-app>

对于servlet 3.1(tomcat 8、wildfly 8-11、glassfish/payara 4等),它如下所示:

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

</web-app>

对于servlet 4.0(tomcat 9、wildfly 12-21、glassfish/payara 5等),它如下所示:

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

    <!-- Config here. -->

</web-app>

对于servlet 5.0(tomcat 10、wildfly 22、glassfish/payara 6等),它如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="https://jakarta.ee/xml/ns/jakartaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
    version="5.0">

    <!-- Config here. -->

</web-app>

当使用JSTL1.1或更新版本时,您需要确保 web.xml 声明的方式使webapp至少以Servlet2.4模式运行,否则el表达式在webapp中不起作用。
当仍然使用servlet 2.3或更旧版本时 <!DOCTYPE><web-app> 在里面 web.xml ,即使您已经有了Servlet2.4或更新的xsd,它仍将被迫在Servlet2.3或更旧的MODU中运行,从而导致el表达式失败。
技术原因是,el最初是JSTL1.0的一部分,在Servlet2.3/JSP1.2及更早版本中不可用。在JSTL1.1中,el从jstl中删除,并集成到JSP2.0中,后者与Servlet2.4一起使用。那么,如果你的 web.xml 声明在Servlet2.3或更旧的MODU中运行webapp,那么jsp将期望在jstl库中找到el,但如果它是一个较新的jstl版本,缺少el,这将反过来失败。

另见:

JSPEL、JSFEL和统一el之间的区别——了解el的历史
我们的jstl wiki页面

pu82cl6c

pu82cl6c2#

对于web.xml文件(version=“3.0”),我必须在tomcat服务器v.8而不是v.7上运行应用程序,否则我会遇到与您相同的问题。希望这对某人有帮助。。。

<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
xvw2m8pv

xvw2m8pv3#

背景 <%@ page isELIgnored="false" %> 这一页的顶部对我有帮助。我不知道为什么这是我的问题的根源。还不清楚为什么。

ubby3x7f

ubby3x7f4#

尝试将jdbc驱动程序类放置在web inf->lib文件夹中,并检查所使用的servlet和jar文件的版本。在我的例子中,我使用了mssql-jdbc-8.2.2.jar,并在pom.xml中对其进行了更新

2cmtqfgy

2cmtqfgy5#

我的jsp页面也无法识别<c:choose></:choose>。始终执行错误条件,即<c:否则>。这就是正在发生的事情。
这是一个内部jsp页面,即

<jsp:include page="your-inner-page.jsp"/>

内部jsp是先加载的,没有下面的标记库。它们被放置在外部jsp上。将它们添加到内部对我很有效。

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

相关问题