Struts2标签库(3):利用<s:property.../>标签访问Struts2的命名对象
2013-06-25 13:03
399 查看
start.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <title>Insert title here</title> </head> <body> <form action="sample" method="post"> username:<input type="text" name="username"><br> <input type="submit" value="confirm"> </form> </body> </html>struts.xml :
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts> <package name="demo" extends="struts-default"> <action name="sample" class="action.SampleAction"> <result name="success">/showInfo.jsp</result> </action> </package> </struts>SampleAction.java :
public class SampleAction { private String username; private String msg; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String execute(){ System.out.println("username:"+username); msg="Action Value Message"; Map<String,Object> request= (Map<String,Object>)ActionContext.getContext().get("request"); request.put("msg","Request Value Message"); Map<String,Object> session=ActionContext.getContext().getSession(); session.put("msg","Session Value Message"); Map<String,Object> application=ActionContext.getContext().getApplication(); application.put("msg","Application Value Message"); return "success"; } }showInfo.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Insert title here</title> </head> <body> <b>action message</b>:<s:property value="msg"/><br> <b>request message</b>:<s:property value="#request.msg"/><br> <b>session message</b>:<s:property value="#session.msg"/><br> <b>application message</b>:<s:property value="#application.msg"/><br> <b>attr message</b>:<s:property value="#attr.msg"/><br> <b>action parameters</b>:<s:property value="username"/><br> <b>context parameters</b>:<s:property value="#parameters.username"/><br> <s:debug></s:debug> </body> </html>
相关文章推荐
- Struts2学习笔记(七):OGNL之<s:property>标签访问值栈(value Stack)对象属性
- struts2利用<s:fielderror/>等标签详细地控制错误消息输出格式
- Struts2 <s:property /> 标签用法
- struts2利用<s:fielderror/>等标签详细地控制错误消息输出格式
- struts2 标签之<s:property />
- struts2 <s:property/>标签的使用--输出时间格式转换
- struts2 用标签 <s:property value='[]'/> 取值 json 含有转义字符的解决方法
- struts2 <s:property>标签的escape属性
- 开发日志:使用struts2标签[<s:if><s:property>等]获取boolean属性需注意
- struts2标签<s:property value=""/> ognl和el .
- struts2 <s:property/>标签的使用
- struts2 <debug>标签报错:Caught an exception while getting the property values of null
- struts2标签<s:property value=""/> ognl和el
- struts2 <s:property/>标签的使用--输出时间格式转换
- struts2 <s:property/>标签的使用--输出时间格式转换
- Struts2的标签显示日期、<s:debug>标签、<s:property>使用技巧
- struts2 中<s:select>标签的用法
- Struts2中<s:select>标签用法
- ssh错误总结1.1----关与struts2中极为恶心的<s:action>标签问题
- Struts2 中利用 <s:iterator标签 批量输出 <input type="checkbox">判读是否被选中