[b]UserAction.java[/b]
[b]struts.xml[/b]
[b]index.jsp[/b]
[b]user_success.jsp[/b]
package com.hugui.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String execute() throws Exception {
return "success";
}
}
[b]struts.xml[/b]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/user" extends="struts-default">
<action name="user" class="com.hugui.struts2.user.action.UserAction">
<!-- 在客户端转向不是同一个request,所以要传递参数,如果是服务器端转向,则不需要传递,因为服务器端转向时共享同一个request -->
<result type="redirect">/user_success.jsp?t=${type}</result>
</action>
</package>
</struts>
[b]index.jsp[/b]
<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<% String context = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>
向结果传参数
<ol>
<li><a href="user/user?type=1">传参数</a></li>
</ol>
</body>
</html>
[b]user_success.jsp[/b]
<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>UserSuccess</title>
</head>
<body>
User Success!
from valuestack: <s:property value="t"/><br/>
<!-- 由于访问的是jsp,所以值栈中是空的,但可以从Context中取得 -->
from actioncontext: <s:property value="#parameters.t"/>
<s:debug></s:debug>
</body>
</html>