星空网 > 软件开发 > ASP.net

struts2 的action 向页面传值

 

写一个Action类:
public class LoginAction{public String execute(){return SUCCESS;}public void setValue(SomeBean value){this.value=value;}public SomeBean getValue(){return this.value;}private SomeBean value;}

  

再写出Bean类:
public class SomeBean{public String getName(){}public void setName(String name){}}

  

方法一:
使用OGNL表达式。你可以使用struts自带的标签,他们都支持OGNL,比如s:property。举个例子:
<!--test.jsp--><%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags" %><s:property value="value.name"/>

你访问LoginAction的时候s:property标签就会显示getValue().getName();
如果你想了解更多的struts2标签和OGNL表达式建议去找更详尽的资料。

  

方法二:
当然是使用JSP本身的性质了。通过request和session来获取值。
我们把Action类改一下:
public class LoginAction{public string execute(){SomeBean value=new SomeBean();value.setName("sfsfjsfje");ActionContext context=ActionContext.getContext();//往request里放attributecontext.put("value",value);//往session里放context.getSession().put("value",value);return SUCCESS;}}

  

接下来我们改页面:
<!-- test.jsp --><%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags" %><%= ((SomeBean) request.getAttribute("value")).getName() %><%= ((SomeBean) session.get("value")).getName() %>

  




原标题:struts2 的action 向页面传值

关键词:Struts

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

日本黄金周:https://www.ikjzd.com/w/1573201564039634945
日本毕业季:https://www.ikjzd.com/w/1573201568242327553
日本商标局:https://www.ikjzd.com/w/1573201569278320642
顺通转运:https://www.ikjzd.com/w/1573201570809241602
四通转运:https://www.ikjzd.com/w/1573201571781976065
J&P会计师楼:https://www.ikjzd.com/w/1573201572767981570
昆明旅游索道公司 昆明旅游索道公司有哪些:https://www.vstour.cn/a/406243.html
太仓美食网(探寻太仓最美味的美食):https://www.vstour.cn/a/406244.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流