平民王子 发表于 2013-2-6 11:06:14

Struts2向结果传参数

JSP请求页面(传参)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>    <base href="<%=basePath%>">      <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head>    <body>向结果传参数<ol><li><a href="user/user?type=1">传参数</a></li></ol></body></html> 



struts.xml的配置(接收jsp传来的参数)
<?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.i18n.encoding" value="UTF-8"></constant><constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>    <package name="user" extends="struts-default" namespace="/user">      <action name="user" class="com.lbx.action.UserAction">      <result type="redirect">/success.jsp?t=${type}</result>      </action>    </package>    </struts> 
Action的处理为参数体统set和get方法
package com.lbx.action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class UserAction extends ActionSupport{private int type;public int getType() {return type;}public void setType(int type) {this.type = type;}@Overridepublic String execute() throws Exception {System.out.println("UserAction.execute()");return SUCCESS;}} 



success.jsp页面(读出传过来的值)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib prefix="s" uri="/struts-tags"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>    <base href="<%=basePath%>">      <title>My JSP 'success.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head>    <body>    User Success!from valuestack: <s:property value="t"/><br/>from actioncontext: <s:property value="#parameters.t"/><s:debug></s:debug></body></html> 


 
页: [1]
查看完整版本: Struts2向结果传参数