将结果显示为表格的首选方式是什么?
我有一个填充数据库结果的操作。现在,我看到了一种方法,那就是制作 Action ServletRequestAware,将填充的列表设置为请求属性并将其显示在 jsp 中。
既然struts2引入了很多改进,那么还有其他方法可以做到这一点吗?我首先想到的是使用displayTag并将Action的返回类型更改为List,但这似乎不起作用。
感谢您提前的回复。
I have an action that populates the result from the DB. Right now, I see a way of doing it and that is to make the Action ServletRequestAware, set the populated list as a request attribute and show it in jsp.
Since a lot of improvements have been introduced into struts2, is there any other way of doing that? The first thing that comes to my mind is to use displayTag and change the return type of Action to a List, but that does not seem to work.
Thanks for any replies in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题不清楚,你应该读一些关于Struts2的书来了解总体思路。
无需使 Action ServletRequestAware。从 http 参数到 actions 字段的映射是通过 Param 拦截器自动完成的(已在默认配置中设置)。 Struts2 的要点之一是将操作与 http 协议解耦,您不应该(通常)在操作中执行任何与 http 相关的操作。
通常,在您的操作
execute()
方法(或其他方法)中,您将从数据库获取要显示的数据,并将其设置为操作的一个属性,以便可以从某些 getter 访问。然后,在您的视图页面(JSP 或其他页面)中您将显示它。您可以使用 displayTag,但首先您会更喜欢“手动”显示它,以了解所涉及的内容。例如,请参见此处 http://www.roseindia.net/struts/ struts2/struts2controltags/iterator-tag.shtml
要手动显示表格,另请参阅此示例 http://www.vaannila.com/struts-2/struts-2-example/struts-2-crud-example-1.html ,搜索
You question is unclear, you should read some book about Struts2 to get the general idea.
No need to make the Action ServletRequestAware. The mapping from http parameters to actions fields is automatically done via the Param interceptor (already set in the default configuration). And one of the points of Struts2 is decoupling the action from the http protocol, you should not (typically) do anything related to http in your action.
Tipically, in your action
execute()
method (or whatever) you'll get the data to display from the DB and set it as one property of your action, so that is accesable from some getter.Then, in your view page (JSP or whatever) you'll display it. You can use displayTag, but first you'll prefer to display it "manually", to understand what's involved. See for example here http://www.roseindia.net/struts/struts2/struts2controltags/iterator-tag.shtml
For manually displaying a table, also see this example http://www.vaannila.com/struts-2/struts-2-example/struts-2-crud-example-1.html , search for the
<table class="userTable>
tag.