How to pass object from action class to JSP using Bean in Struts2?

☆樱花仙子☆ 提交于 2019-12-06 08:47:35

First time you instantiate the bean in the action, second time in the JSP. It's not the same bean you've populated in the action, and doesn't contain the values. If you want to get the values from the first bean then you should create mutators to a variable that hold the instance of the bean. You should also create mutators to access the properties of that bean. In the JSP you have access to the first bean because the action instance is on the top of the valueStack. Just use

<s:property value="elasticitiesBean.auto_Auto_cost_peak" />

Note, that without # OGNL will not search the other variables, it will look directly into the valueStack. But don't do it inside the bean tag, because the new (second) instance is pushed to the valueStack and the search is performed from top to bottom, thus it could match the properties of the bean. Just remove the bean tag.

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