Struts逻辑问题

发布于 2024-07-07 02:47:56 字数 1305 浏览 5 评论 0原文

为什么下面的代码不起作用? 这个想法是,页面检查自上次刷新页面以来下拉变量是否发生了变化。

 <logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


 <logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
type="java.lang.String" toScope = "session" />              
</logic:equal>

<-- when you fisrt access this page from the above are run -->

 <bean:define id="NewDropDownValue" name="smlMoverDetailForm"
  property="moverChangeType" type="java.lang.String" toScope = "sess

<-- this happens everytime the page is refreshed-->

   <logic:equal name= DropDownValue   value = NewDropDownValue>
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
  property="empFDJoiningDate" type="java.lang.String" toScope = "session" />
   </logic:equal> 

    <logic:notEqual name="DropDownValue"   value = "NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
    property="moverChangeType" type="java.lang.String" toScope = "session"
     />              
    </logic:notEqual>    

Why doesn't the code below work? The idea is that the page checks to see if the dropdown variable has changes since you last refreshed the page.

 <logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


 <logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
type="java.lang.String" toScope = "session" />              
</logic:equal>

<-- when you fisrt access this page from the above are run -->

 <bean:define id="NewDropDownValue" name="smlMoverDetailForm"
  property="moverChangeType" type="java.lang.String" toScope = "sess

<-- this happens everytime the page is refreshed-->

   <logic:equal name= DropDownValue   value = NewDropDownValue>
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
  property="empFDJoiningDate" type="java.lang.String" toScope = "session" />
   </logic:equal> 

    <logic:notEqual name="DropDownValue"   value = "NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
    property="moverChangeType" type="java.lang.String" toScope = "session"
     />              
    </logic:notEqual>    

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

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

发布评论

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

评论(5

永不分离 2024-07-14 02:47:56

您已经意识到,您的 bean:define - 至少在您在这里提出的问题中 - 是有缺陷的?

toScope="sess

很可能不是您想要的 - 它甚至不会终止标签。 但这可能是在 StackOverflow 中格式化的...此外,其他答案中也提到了缺少的引号。

错误可能是 value 属性的使用:根据 http ://struts.apache.org/1.2.x/userGuide/struts-logic.html#equal value 是该标签的其他属性指定的变量的常量值,因此

,假设您已经定义了一个名为 NewDropDownValue 的 bean,您可能想要评估

<logic:equal name="DropDownValue" value="<%=NewDropDownValue/>">

编辑:此外,我不记得当您仅有条件地定义一个 bean 时会发生什么 - 您的 bean 是在逻辑中定义的:equal 块可能会或可能不会被评估。 它可能是合法的并且有明确的结果,我只是不记得了......

You have realized, that your bean:define - at least in your question stated here - is flawed?

toScope="sess

is most likely not what you want - it doesn't even terminate the tag. But this may be formatting in StackOverflow... Also, the missing quotes have been mentioned in other answers.

The error may be the use of the value property: According to http://struts.apache.org/1.2.x/userGuide/struts-logic.html#equal value is The constant value to which the variable, specified by other attribute(s) of this tag, will be compared.

Thus, given that you've defined a bean named NewDropDownValue you might want to evaluate

<logic:equal name="DropDownValue" value="<%=NewDropDownValue/>">

Edit: Additionally I can't remember what happens when you only conditionally define a bean - your bean is defined inside a logic:equal block that might or might not be evaluated. It might be legal and have defined results, I just can't remember...

毁梦 2024-07-14 02:47:56
<logic:equal name= DropDownValue   value = NewDropDownValue>

我不确定这是否是您的问题(请描述它如何不起作用),但上面的内容不是有效的 xml:它需要在属性值周围加上引号。

<logic:equal name= DropDownValue   value = NewDropDownValue>

I'm not sure if this is your problem (describe how it doesn't work please), but the above is not valid xml: it needs quotes around the attribute values.

任谁 2024-07-14 02:47:56

问题是正如您所描述的,我无法获取逻辑标签来评估定义的 bean 中保存的值。

The problem is as your describe i can't get the logic tags to evaluate the values held in the defined beans.

打小就很酷 2024-07-14 02:47:56

实际上,我真的不明白你想要什么,但这里有一些伪代码(删除那些危险的尖括号)问题中的代码

if result == -1
   define JOININGDATE
end
if result == -1
   define DropDownValue
end

这可能是一个错误(你可能想检查一次“等于”,一次检查“does”不等于')或者写得更短更清晰

if result == -1
   define JOININGDATE
   define DropDownValue
end
// otherwise don't define both values

如果您将一些输出放置在这些逻辑标签内并发布输出和更多的上下文(例如实际的),您的问题可能会得到更好的答案(或者由您自己回答)参数值——什么是“结果”)。 但是,您是通过未注册的帐户发布的,并且已经有一段时间没有被看到了......

Actually, I don't really get what you want, but here's some pseudocode (removing those dangerous pointy brackets) of your code in the question

if result == -1
   define JOININGDATE
end
if result == -1
   define DropDownValue
end

This might be an error (you might want to check once for 'equals' and once for 'does not equal') or be written shorter and more clear

if result == -1
   define JOININGDATE
   define DropDownValue
end
// otherwise don't define both values

Your question might get better answers (or be answered by you yourself) if you placed some output inside of those logic tags and post both the output and a bit more of the context (e.g. actual parameter values -- what is 'Result'). But then - you've posted from an unregistered account and have not been seen for some time...

誰認得朕 2024-07-14 02:47:56

试试这个:

<logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


<logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
        type="java.lang.String" toScope = "session" />              
</logic:equal>

<!-- when you fisrt access this page from the above are run -->

<bean:define id="NewDropDownValue" name="smlMoverDetailForm"
    property="moverChangeType" type="java.lang.String" toScope = "session"/>

<!-- this happens everytime the page is refreshed-->

<logic:equal name="DropDownValue" value="<%=request.getSession().getAttribute("NewDropDownValue").toString()%>">
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
        property="empFDJoiningDate" type="java.lang.String" toScope ="session" />
</logic:equal>

<logic:notEqual name="DropDownValue" value="NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
        property="moverChangeType" type="java.lang.String" toScope = "session"/>              
</logic:notEqual>

错误更正:

  • 注释格式不正确
  • 第三个未正确结束
  • 更改获取 NewDropDownValue 的方式

我认为这些更改将使其正确运行。

Try this:

<logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


<logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
        type="java.lang.String" toScope = "session" />              
</logic:equal>

<!-- when you fisrt access this page from the above are run -->

<bean:define id="NewDropDownValue" name="smlMoverDetailForm"
    property="moverChangeType" type="java.lang.String" toScope = "session"/>

<!-- this happens everytime the page is refreshed-->

<logic:equal name="DropDownValue" value="<%=request.getSession().getAttribute("NewDropDownValue").toString()%>">
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
        property="empFDJoiningDate" type="java.lang.String" toScope ="session" />
</logic:equal>

<logic:notEqual name="DropDownValue" value="NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
        property="moverChangeType" type="java.lang.String" toScope = "session"/>              
</logic:notEqual>

Errors corrected:

  • Comments were not well formed
  • Third was not correctly ended
  • Change the way to get NewDropDownValue

I think those changements will make it runs correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文