对struts2中OGNL数据处理的一点理解
在MVC模式的view层中,jsp中的form表单中元素如input等,都使用OGNL的表达式作为name的值。而在form提交时,这些值都会被设置到Action中的java对象中。而当Action转向到JSP时,struts2的Tag又可以从Action的java对象中,通过OGNL进行取值。 [code="java"]
user name: department name:
[/code] [code="java"]public class OgnlAction extends ActionSupport { private static final Log logger = LogFactory.getLog(OgnlAction.class); private User user; private Department department; /* (non-Javadoc) * @see com.opensymphony.xwork2.ActionSupport#execute() */ @Override public String execute() throws Exception { logger.info("user name:" + user.getName()); // -> downpour logger.info("department name:" + department.getName()); // -> dev return super.execute(); } // setter and getters } [/code] [code="java"] user name: department name: [/code]