在JSP中,”var”是什么意思?

huangapple go评论68阅读模式
英文:

What does "var" mean in JSP?

问题

我试图理解项目中调用主代码的jsp代码,该代码从主代码中调用一个方法。我有这样的jsp代码:

<s:iterator value="eventsDisplay" var="event">
    <s:set var="eventExtra" value="%{getEventExtra(#event)}" />

这个 getEventExtra 在主代码中是这样的:

public Map<String, String> getEventExtra(AbstractEventDisplay eventDisplay) {
        Map<String, String> map = new HashMap<>();
        ...
        ...

我猜测jsp代码和主代码之间存在联系,但在 getEventExtra 方法中,参数从哪里来呢?我看到在jsp中有 event,它被传递进来,但我不知道 var 是什么意思。AbstractEventDisplay 大致如下:

public abstract class AbstractEventDisplay implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private Date updateTimestamp;

    private String type;

    private String userName;
    private boolean userDeleted;
    ...
    ...
    ...

有人可以解释一下在jsp中的 event(或者我猜测是从网页中来的?)是如何转化为Java对象的吗?

英文:

I am trying to understand jsp code in the project that calls a method from main code. I have jsp code like this:

<s:iterator value="eventsDisplay" var="event">
    <s:set var="eventExtra" value="%{getEventExtra(#event)}" />

This getEventExtra is in the main code like this:

public Map<String, String> getEventExtra(AbstractEventDisplay eventDisplay) {
        Map<String, String> map = new HashMap<>();
        ...
        ...

I am guessing there is connection between jsp code and main code, but in getEventExtra method, where does parameter comes from? I see that in jsp we got event and it is passed in, but I don't know what var means. AbstractEventDisplay is something like this:

public abstract class AbstractEventDisplay implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private Date updateTimestamp;

    private String type;

    private String userName;
    private boolean userDeleted;
    ...
    ...
    ...

Can anyone explain to me how event in jsp (or I am guessing from webpage?) is translated into java object.

答案1

得分: 1

你正在使用set标签。对于该标签,var的值是您存储信息的变量名称。<s:set var="eventExtra" value="%{getEventExtra(#event)}" />的意思是“创建一个名为eventExtra的变量,并将调用getEventExtra(#event)的结果存储在其中”。

英文:

You are using the set tag. For that tag, the value of var is the name of the variable where you store information. &lt;s:set var=&quot;eventExtra&quot; value=&quot;%{getEventExtra(#event)}&quot; /&gt;means "create a variable named eventExtra and store the result of calling getEventExtra(#event) in it".

huangapple
  • 本文由 发表于 2020年8月21日 21:52:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63524166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定