struts2 s:if 测试的问题
test.jsp:
%%%%%%%%%%%%%
< s:property value="#parameters.type"/>
< s:if test="#parameters.type == 1">
< select>
< option value="-1">
请选择
< /option>
< option value="1" selected>
收件箱
< /option>
< option value="2">
发件箱
< /option>
< /select>
< /s:if>
%%%%%%%%%%%%%%
当通过test.jsp?type=1访问该页面时 s:if 测试为 false,因此不显示选择列表。 有人能告诉我为什么吗?谢谢!
test.jsp:
%%%%%%%%%%%%%
< s:property value="#parameters.type"/>
< s:if test="#parameters.type == 1">
< select>
< option value="-1">
请选择
< /option>
< option value="1" selected>
收件箱
< /option>
< option value="2">
发件箱
< /option>
< /select>
< /s:if>
%%%%%%%%%%%%%%
when this page is accessed by test.jsp?type=1
the s:if test is false, so the select list is not showed.
Can somebody tell me why? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望你明白你的代码并不是很好的struts2实践。这不是 Struts2 正常使用的方式。您的http参数通常应该映射到您的操作字段,并且(在您的操作完成其工作之后)您的jsp应该显示从同一操作中提取它们的结果。通常情况下。通常,您不需要访问 jsp 中的 http 参数,也不需要执行任何逻辑(除了非常琐碎的逻辑)。
不管怎样,也许你的测试中的问题是
#parameters.type
是一个原始字符串,而你正在将它与一个数字进行比较。 (这是违反正常 Struts2 流程的众多问题之一 - 从普通字符串到更有意义的类型的转换通常是在该映射中通过参数拦截器完成的。如果您有一个正确的整数“类型”字段,则不会出现该问题在你的操作中,在你的jsp中你要求它)你尝试过#parameters.type == '1'
吗?I hope you understand that your code is not good struts2 practice. That's not the way Struts2 is supposed to be used normally. Your http parameters should normally be mapped to your action fields, and (after your action has done its work) your jsp should show the results pulling them from the same action. Normally. And normally, you should not need to access http parameters in your jsp, nor do any logic (except for very trivial ones).
Anyway, perhaps the problem in your test is that
#parameters.type
is a raw string, and you are comparing it to a number. (That's one of the many problems of violating the normal Struts2 flow - the convertion from plain strings to more meaningful types is normally done in that mapping, by the param interceptor. The problem would not arise is you had a proper integer 'type' field in your action, and in your jsp you ask for it) Did you try#parameters.type == '1'
?我已经解决了这个问题。只需将“#parameters.type”替换为“#parameters.type[0]”即可。
然后测试就可以了!
那是因为 struts2 将 URL 中的参数视为数组。
I've solved the problem. just substitute the "#parameters.type" with "#parameters.type[0]".
Then the test works!
Thats because struts2 treat the parameters form URL as an array.