JSP EL $ {stuff}语法不起作用 [英] JSP EL ${stuff} syntax not working

查看:172
本文介绍了JSP EL $ {stuff}语法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题。第一个是我使用JSP而我无法解决。第二个是我得到一个奇怪的行为。

I have two problems. The first one is that I'm using JSP and that I can't solve. The second one is that I'm getting an odd behavior.

当我把它放在我的servlet的doGet()方法中时

When I put this in the doGet() method of my servlet

req.setAttribute("test", "SARASA");
req.getRequestDispatcher("WEB-INF/main.jsp").forward(req, resp);

这在WEB-INF / main.jsp中:

And this in "WEB-INF/main.jsp":

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%= request.getAttribute("test") %>
<c:out value="${test}"/>

输出为:

SARASA ${test}

我不知道我在做什么做错了......这可能是什么原因?

I don't know what I'm doing wrong... what can be the reason for this?

更新:我解决了它添加

<%@ page isELIgnored="false" %>

在我需要它的每个JSP中。奇怪的是,我在另一个项目中并不需要使用一些非常相似的web.xml和pom.xml文件(我正在使用maven)。

In each JSP where I needed it. Oddly, I didn't needed that in another project using some very similar web.xml and pom.xml files (I'm using maven).

推荐答案

您的web.xml可能引用了Servlet 2.3规范,其中 isELIgnored 设置为 true 默认情况下。如果您引用Servlet 2.4规范,默认情况下 isELIgnored 将设置为 false

Your web.xml is probably referencing the Servlet 2.3 spec, in which isELIgnored is set to true by default. If you reference the Servlet 2.4 spec instead, isELIgnored will be set to false by default.

如果你想引用Servlet 2.4规范,你的web.xml标题应如下所示:

If you want to reference the Servlet 2.4 spec, your web.xml header should look something like this:

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

这篇关于JSP EL $ {stuff}语法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆