<s:action>标签的使用
2014-06-15 11:37
489 查看
在jsp页面中直接调用Action
①先编写action类:ActionTagAction.java
package action;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ActionTagAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public String doDefault() throws Exception {
// TODO Auto-generated method stub
ServletActionContext.getRequest().setAttribute("stringByAction", "这是执行actiondefault方法时的输出");
return "done";
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
ServletActionContext.getRequest().setAttribute("stringByAction", "t方法时的输出");
return "done";
}
}
②在struts.xml中修改配置,在<package>标签体内加入如下配置
<action name="actionTagAction1" class="action.ActionTagAction">
<result name="done">/success.jsp</result>
</action>
③编写success.jsp页面
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
执行成功的结果页面内容
</body>
</html>
④编写调用页面DATAtage.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>数据标签</title>
</head>
<body>
<s:action name="actionTagAction1" executeResult="true"/>
<br>
<s:action name="actionTagAction1!default" executeResult="false">
<s:property value="#attr.stringByAction"/>
</s:action>
</body>
</html>
运行如图:
①先编写action类:ActionTagAction.java
package action;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ActionTagAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public String doDefault() throws Exception {
// TODO Auto-generated method stub
ServletActionContext.getRequest().setAttribute("stringByAction", "这是执行actiondefault方法时的输出");
return "done";
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
ServletActionContext.getRequest().setAttribute("stringByAction", "t方法时的输出");
return "done";
}
}
②在struts.xml中修改配置,在<package>标签体内加入如下配置
<action name="actionTagAction1" class="action.ActionTagAction">
<result name="done">/success.jsp</result>
</action>
③编写success.jsp页面
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
执行成功的结果页面内容
</body>
</html>
④编写调用页面DATAtage.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>数据标签</title>
</head>
<body>
<s:action name="actionTagAction1" executeResult="true"/>
<br>
<s:action name="actionTagAction1!default" executeResult="false">
<s:property value="#attr.stringByAction"/>
</s:action>
</body>
</html>
运行如图:
相关文章推荐
- struts-1.3.10中的<action-mappings> <action>标签中<set-property>的用法
- <c:redirect>标签的使用
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- <c:forEach>标签的使用方法
- <img>标签加入onerror事件,如果没有找到图片,则使用默认图片
- 使用html <a href=""/>标签连接action的方法
- AndroidMainifest标签使用说明1——<action>
- 使用<a>标签提交action会执行两次后台方法的原因(反射机制小实例问题的解决)
- 使用html <a href=""/>标签连接action的方法
- <c:forEach>标签,需要与el表达式联合使用
- <html:link>超链接标签的使用
- <!DOCTYPE> 标签的深度剖析以及使用选择
- <s:action>标签的用法
- Struts2的<s:if> 标签判断Action中的字段是否为null或者空字符串的方法
- JSP中使用html中的<base>标签不起作用
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用
- <base>标签的使用
- 一段可以使用的 hibernate获得对象->action存入List->jsp页面用<s:iterator>迭代的代码
- 使用HTML5的<vedio>标签插入视频,兼容主流浏览器
- <fmt:formatDate/> 标签使用