如何在struts2的应用范围内设置一个值? [英] How to set a value in application scope in struts2?

查看:30
本文介绍了如何在struts2的应用范围内设置一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,我的应用程序的所有用户都可以访问它.我目前正在将它添加到特定用户的会话中.但我希望它在应用程序范围内而不是会话范围内.请帮助提供参考/链接任何例子

I have a list that is accessible to all user of my application.I am currently adding it to session of a particular user.But i want it to be in application scope rather than session scope.Please help also provide reference/link to any example

推荐答案

我不确定您想如何使用该列表:您想将该列表显示到屏幕上,或者您只需要它作为配置.要显示它,您可以:

I am not sure how you want to use the list: you want to display that list to the screen or you just need it as configuration. To display it you could:

  • 在您的 Action 中静态创建您的列表,然后在 JSP 中显示它
  • 您可以从数据库中动态获取列表,然后将其显示在 JSP 中
  • create your list statically in your Action, then display it in the JSP
  • you could take the list dynamically from a database, then display it in the JSP

将其用作配置:一些数据可以在初始化时在应用程序级别可用,但这些是配置参数.更多信息在这里:

To use it as configuration: some data can be made available at application level at initialization, but those are configuration params. More info here:

使用 ServletContext 是您可以动态设置参数到 servlet 从您的代码的唯一方法:servletContext.setAttribute().更多信息在这里:

Using the ServletContext is the only way you can set parameters dynamically to the servlet from your code: servletContext.setAttribute(). More info here:

这篇关于如何在struts2的应用范围内设置一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆