How to set a value in application scope in struts2?

荒凉一梦 提交于 2019-12-06 14:01:37
herti

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:

  • 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:

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

In action you can use :

ServletActionContext.getContext().getApplication().put("myVar", myObj);

In order to set in a JSP, you can use the <s:set> tag as :

<s:set name="myVar" scope="application" value="myObj"/>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!