使用OGNL标签:需要导入Struts2标签库<%@taglib uri="/struts-tags" prefix="s"%>
1.访问ACTION的普通属性
例如在action中定义一个变量
private String userName;
get/set....省略
在Jsp页面直接通过<s:property value="userName"/>标签访问
2.访问ACTION里的复杂属性
例如在action中定义一个对象
private 对象 user;
get/set....省略
在Jsp页面通过 <s:property value="user.userName" />对象名点属性名访问,需要对象
提供get/set方法
3.访问对象的普通方法 <s:property value="xxx.methodName()"/>
4.访问ACTION的普通方法<s:property value="methodName()" />
5.使用#读取parameters request session application 范围内的值()
<s:property value="#request.id"/> 相当于 request.getAttribute("id")
<s:property value="#parameters.id"/> 相当于 request.getParameter("id")
<s:property value="#session.id"/> 相当于 session.getAttribute("id")
<s:property value="#application.id"/> 相当于 application.getAttribute("id")
<s:property value="#attr.id"/> 依次搜索PageContext HttpServletRequest
HttpSession ServletContext 范围 ,查找属性,找到为止 类似JSTL的${}
1.访问ACTION的普通属性
例如在action中定义一个变量
private String userName;
get/set....省略
在Jsp页面直接通过<s:property value="userName"/>标签访问
2.访问ACTION里的复杂属性
例如在action中定义一个对象
private 对象 user;
get/set....省略
在Jsp页面通过 <s:property value="user.userName" />对象名点属性名访问,需要对象
提供get/set方法
3.访问对象的普通方法 <s:property value="xxx.methodName()"/>
4.访问ACTION的普通方法<s:property value="methodName()" />
5.使用#读取parameters request session application 范围内的值()
<s:property value="#request.id"/> 相当于 request.getAttribute("id")
<s:property value="#parameters.id"/> 相当于 request.getParameter("id")
<s:property value="#session.id"/> 相当于 session.getAttribute("id")
<s:property value="#application.id"/> 相当于 application.getAttribute("id")
<s:property value="#attr.id"/> 依次搜索PageContext HttpServletRequest
HttpSession ServletContext 范围 ,查找属性,找到为止 类似JSTL的${}