在 JSP 脚本分隔符中使用 OGNL [英] Using OGNL inside a JSP scripting delimiters

查看:38
本文介绍了在 JSP 脚本分隔符中使用 OGNL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在脚本分隔符中使用 OGNL?

<option value="<%=car.getType()["#incr.index"]%>"><s:property value="arr"/></选项></s:迭代器>

这是我的Car结构:

private String[] carNames = {"A", "B", "C"};公共静态整数[] getType() {返回新整数[]{新整数(Global.DISEL),新整数(Global.TESLA),新整数(Global.HYBRID)};}//getter 和 setter

解决方案

在脚本定界符中,您不能使用 OGNL.您应该删除 scriptlet 并将其替换为 标记或使用 ${}.

它展示了如何在 HTML 标签中使用 OGNL.

如果您正在使用 select 标签,我建议您阅读 Struts2 select 标签 - 动态添加选项.>

How can I use the OGNL inside a scripting delimiters?

<s:iterator var="arr" value="%{carNames}" status="incr">        
    <option value="<%=car.getType()["#incr.index"]%>" >
        <s:property value="arr"/>
    </option>           
</s:iterator>

This is my Car structure:

private String[] carNames = {"A", "B", "C"};

public static Integer[] getType() {
    return new Integer[]{
        new Integer(Global.DISEL),
        new Integer(Global.TESLA),
        new Integer(Global.HYBRID)
    };
 }

 //getter and setter

解决方案

In scripting delimiters you can't use OGNL. You should remove scriptlets an replace it with <s:property> tag or use ${}.

<option value="<s:property value='%{car.type[#incr.index]}'/>">

It shows how to use OGNL in HTML tags.

If you are working with select tag, I recommend you to read Struts2 select tag - Dynamically add options.

这篇关于在 JSP 脚本分隔符中使用 OGNL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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