Struts2 脚本
将 struts2 与 jsp 和标准 struts 标记库结合使用。
我试图在页面加载时动态隐藏 DIV,但仍将其发送到浏览器。这样我以后就可以通过 javascript 显示它。
请求对象一和二不容易通过 jsp:usebean 标记引用。 (它们是枚举,无法实例化)我尝试使用 s:if 标签或 c:if 标签的组合,但它看起来很丑陋。
<%
String displayStr = "display: none;";
if(request.getAttribute("one") != null || request.getAttribute("two") != null ) {
displayStr = "display: block;";
}
%>
<div id="next" style="<%=displayStr %>">
对于更好的方法有什么建议吗?
Using struts2 with jsp with standard struts tag libraries.
I'm trying to dynamically hide a DIV on page load, but still send it to the browser. This is so I can show it later via javascript.
The request objects one and two are not easily referenced via a jsp:usebean tag. (They are enums and cannot be instantiated) I tried using a combination of s:if tags or c:if tags and it just looks ugly.
<%
String displayStr = "display: none;";
if(request.getAttribute("one") != null || request.getAttribute("two") != null ) {
displayStr = "display: block;";
}
%>
<div id="next" style="<%=displayStr %>">
Any suggestions for a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 JSTL:
Using JSTL:
呃,伙计,那太丑了。让我吞下去,给你一个替代方案......
嗯...例如,您可以编写:
或者然后
在您的 Action 中提供一个 isDivVisible() 方法,该方法读取参数“one”和“two”(不是来自 httpRequest!)
Ugh, man, that was ugly. Let me swallow, and give you an alternative...
Mmm... for example, you could write:
Or also
And then in your Action provide a
isDivVisible()
method which read the params "one" and "two" (not from the httpRequest!)只需在模板文本中使用纯 EL:
十多年来不鼓励使用 scriptlet。它们应该全部替换为 taglibs(Struts2、JSTL 等)和 EL。只要这是不可能的,那么代码逻辑几乎肯定属于真正的 Java 类,如模型对象、servlet(或 Struts2 操作)等。
Just use plain EL in template text:
Use of scriptlets is discouraged since over a decade. They should be all replaced by taglibs (Struts2, JSTL, etc) and EL. Whenever that's not possible, then the code logic almost certainly belongs in a real Java class, like a model object, a servlet (or Struts2 action), etc.