EL 等效于 <%= object.method(parameter) %>在是 8? [英] EL equivalent of <%= object.method(parameter) %> in WAS 8?

查看:39
本文介绍了EL 等效于 <%= object.method(parameter) %>在是 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说支持参数,但示例使用 hl# 我不知道我在哪里使用 c: 和 $ 而不是来自文档的这个:

The documentation says parameters are supported but the example uses hl and # which are unknown to me where I use c: and $ instead of this which is from the docs:

我所知道的关于 EL 中的 $ vs # 与右值和左值有关,我需要进一步解释何时使用 # 样式.我正在寻找 typ $... 的 EL 表达式如何接受参数,以及如何使用参数调用非 getter 非 setter,例如从请求上下文中的 bean 获取常量静态字符串.

All I know about $ vs # in EL is that is has to do with rvalue and lvalue which I can need a further explanation when to use the # style. I'm looking for how an EL expression of typ $... can take a parameter and how to call non-getters non-setters with a parameter for example fetching a constant static string from a bean in the request context.

# 与 $ 相比有什么作用?如果我想使用 $,如何在 EL 中使用参数?我想迁移到 EL 的 scriptlet 类似于 <%= Constants.CONSTANT %><%= object.method(parameter) %>我想在EL做.

What does # do compared to $? How do I use parameters in EL if I want to use the $? The scriptlets I want to migrate to EL are something like <%= Constants.CONSTANT %>and <%= object.method(parameter) %> that I want to do in EL.

推荐答案

#{} 语法应该用于 仅限 Java EE 的 MVC 框架 JSF.另请参阅JSP EL、JSF EL 和统一 EL 之间的区别.只需坚持旧 JSP 中的 ${} 语法.

The #{} syntax is supposed to be used in the Java EE's MVC framework JSF only. See also Difference between JSP EL, JSF EL and Unified EL. Just stick to ${} syntax in old JSP.

关于调用带参数的方法,这是在 Servlet 3.0/EL 2.2 中引入的.WAS 8 是一个 Servlet 3.0 容器,因此它应该开箱即用地支持它.您只需要确保您的 web.xml 声明为符合 Servlet 3.0 规范版本.否则,容器将以与 web.xml 指示的版本匹配的后备模式运行.正确的 Servlet 3.0 web.xml 声明如下所示:

As to invoking methods with arguments, this is introduced in Servlet 3.0 / EL 2.2. WAS 8 is a Servlet 3.0 container, so it should support it out the box. You only need to make sure that your web.xml is declared conform Servlet 3.0 specification version. Otherwise the container will run in fallback modus matching the version indicated by web.xml. The proper Servlet 3.0 web.xml declaration look like this:

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

这样 ${object.method(param)} 必须工作.

在 EL 中引用常量是另一回事.这将在即将到来的 EL 3.0 中引入,这是未来的一部分Java EE 7/Servlet 3.1(未来的 WAS 9 或 10 可能会支持).有自定义标签库风格的解决方案或将它们保存在 Map 中,所有这些都在这个答案中详细解释:如何在 EL 中引用常量?

Referencing constants in EL is a different story. This will be introduced in the upcoming EL 3.0, which is part of the future Java EE 7 / Servlet 3.1 (and likely the future WAS 9 or 10 would support it). There are solutions in flavor of custom taglibs or by keeping them in a Map, all explained in detail in this answer: How to reference constants in EL?

这篇关于EL 等效于 &amp;lt;%= object.method(parameter) %&gt;在是 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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