簡體   English   中英

比較 JSP 中的 struts ognl 值與 scriptlet 值

[英]Comparing struts ognl value to scriptlet value in JSP

我必須將其與如下值進行比較:

${page_id } ---- <% out.print(a); %>

<c:if test="${page_id != a}">

我怎樣才能做到這一點?

假設“a”是一個 scriptlet 變量。 El 表達式 map 到 scope 中的頁面/請求/會話/應用程序屬性。

${page_id} 大約相當於 pageContext.findAttribute("page_id");

為了能夠比較它們,你需要讓它們進入同一個空間。 一種方法是使用 scriptlet 代碼:

<% pageContext.setAttribute("a", a); %>

您現在應該能夠將 ${a} 作為 EL 表達式進行訪問。 不是首選解決方案,因為它使用 scriptlet 代碼(在 JSP 中要避免的事情)當然可能有更好的方法。 這一切都取決於“a”的值首先來自哪里。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM