您的位置:首页 > 编程语言 > Java开发

<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>

运行如图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jsp struts action