JSP 支柱

发布于 2024-07-07 23:16:41 字数 159 浏览 5 评论 0原文

如何在 JSP <%> 的 scriplet 代码中分配变量 然后使用struts逻辑标签根据scriplet代码块中分配的变量值来做一些事情?

我尝试使用 struts:logic equal 和greaterthan 无济于事......

非常感谢,

How would I assign a variable within scriplet code in JSP <%> and then use struts logic tags to do stuff based on the value of the variable assigned in the scriplet code block?

I have tried using struts:logic equal and greaterthan to no avail....

Many Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赠我空喜 2024-07-14 23:16:41

您想要做的事情(如果我理解正确的话)基本上是这样的:

<% String foo = "Test"; %>
<bean:write name="foo" />

正如您所知,这是行不通的。 这会给出这样的错误:

在任何范围内都找不到 bean foo

我通常做的是将我的数据放入页面范围中,如下所示:(

<% pageContext.setAttribute("foo", "Test"); %>
<bean:write name="foo" />

这是针对 Struts 1.1 的。较新的版本可能提供更好的方法。)

What you are trying to do (if I understand you correct) is basically this:

<% String foo = "Test"; %>
<bean:write name="foo" />

Which, as you already know, doesn't work. That would give an error like this:

Cannot find bean foo in any scope

What I usually do, is to put my data in the page scope like this:

<% pageContext.setAttribute("foo", "Test"); %>
<bean:write name="foo" />

(This is for Struts 1.1. Newer versions may provide a better way to do it.)

冬天旳寂寞 2024-07-14 23:16:41

在 scriptlet 中:

<%
   request.setAttribute("customerName", "rajesh");
%>

您可以签入 struts 逻辑标签,例如,

<logic:match name="customerName" value="Vijay"></logic:match>

In scriptlet:

<%
   request.setAttribute("customerName", "rajesh");
%>

And you can check in struts logic tags like,

<logic:match name="customerName" value="Vijay"></logic:match>
十二 2024-07-14 23:16:41

我猜你会发现这个:

scriptlet 代码 你必须在 JSP 上编写 Java 代码

<%int var=1; %>in jsp its declaration ( <%! int i = 0; %> )

表达式元素可以包含根据 Java 语言规范有效的任何表达式,但不能使用分号来结束表达式,

<p>   Today's date: <%= (new java.util.Date()).toLocaleString()%></p>

谢谢

I guess u find this:

scriptlet code u have to write Java code on JSP

<%int var=1; %>in jsp its declaration ( <%! int i = 0; %> )

The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression

<p>   Today's date: <%= (new java.util.Date()).toLocaleString()%></p>

thanks

或十年 2024-07-14 23:16:41

您可以使用标签在 Struts2 中设置变量。 例如:

<c:set var="contains" value="true" />

可以测试逻辑:

<c:if test="%{#variable=='String 1'}">
    This is String 1
</c:if>

其他来源:
http://www.mkyong.com/struts2/ struts-2-if-elseif-else-tag-example/

必需的标签库:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

You can set a variable in Struts2 using tags. for Example:

<c:set var="contains" value="true" />

logic can be tested:

<c:if test="%{#variable=='String 1'}">
    This is String 1
</c:if>

other sources:
http://www.mkyong.com/struts2/struts-2-if-elseif-else-tag-example/

Required taglib:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文