六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 253|回复: 0

Struts2向结果传参数

[复制链接]

升级  30.33%

87

主题

87

主题

87

主题

举人

Rank: 3Rank: 3

积分
291
 楼主| 发表于 2013-2-6 11:06:14 | 显示全部楼层 |阅读模式
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> 


 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表