struts2下拉
我需要在 struts2 中从列表创建一个下拉菜单。如何创建一个操作类,以便在加载 .jsp 页面时,它首先填充列表?
我找到了这个链接 http://www.mkyong .com/struts2/struts-2-sselect-drop-down-box-example/ ,它也可以工作,但是用户必须转到 http://localhost:8080/Struts2Example/selectAction.action 使其工作,但如果有人直接转到 select.jsp 该怎么办?
I need to create a drop down menu in struts2 from List. How can I create an action class so that when a .jsp page is loaded, it populates the list first?
i found this link http://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/ , it works too but for it work user must go to http://localhost:8080/Struts2Example/selectAction.action to make it work but what if someone were to directly go to select.jsp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是 .jsp,因此您可以在渲染
标记之前使用 scriptlet 加载下拉列表。但是,更好的做法是允许操作执行加载并将 .jsp 文件隐藏在 /WEB-INF 下,这样就无法直接访问它们。执行此操作的常见方法是准备拦截器。
如果您的拦截器堆栈中有它,它会在您的操作调用请求的方法之前自动调用具有以下名称的任何方法:
这意味着您可以在 Action 中执行类似以下操作:
然后您所要做的就是调用 Action 的 view() 方法,并且 Struts 将首先调用prepare。
Since you're using a .jsp, you could load the dropdown with a scriptlet before you render the
<s:select>
tag.However, it's better practice to allow the action to perform the loading and hide the .jsp files under /WEB-INF so they're not directly accessible. A common approach to perform this is the Prepare interceptor.
If you've got it in your interceptor stack, it will automatically invoke any method with the following name in your action before invoking the requested method:
That means you can do something like the following in your Action:
Then all you have to do is call your action's view() method and prepare will be called first by Struts.