
set方法 、get方法是向页面表单的name属性设置值和获取值,getParameters()是获取请求的参数值。
从页面获取参数值就是在action中提供表单name属性的set方法 、get方法。
使用Cookie传递参数 ,a页面保存Cookie,b页面读取,代码如下:
a页面
<html><head>
<title>a</title>
<style type="text/css">
{margin:0}
body {text-align:center;min-width:760px}
div {padding:3px 3px 3px 3px}
#main {width:720px;margin:0 auto;text-align:left;margin-top:30px}
#main div span {width:50px}
</style>
<script type="text/javascript">
/
@param {string} cookieName Cookie名称
@param {string} cookieValue Cookie值
@param {number} nDays Cookie过期天数
/
function SetCookie(cookieName,cookieValue,nDays) {
/当前日期/
var today = new Date();
/Cookie过期时间/
var expire = new Date();
/如果未设置nDays参数或者nDays为0,取默认值1/
if(nDays == null || nDays == 0) nDays = 1;
/计算Cookie过期时间/
expiresetTime(todaygetTime() + 3600000 24 nDays);
/设置Cookie值/
documentcookie = cookieName + "=" + escape(cookieValue)
+ ";expires=" + expiretoGMTString();
}
function login() {
var username = $("user")value;
var password = $("pass")value;
/是否选中7天内无需登录/
var save = $("save")checked;
if(username=="abc" && password=="abc") {
if(save) SetCookie("username",username,7);
else SetCookie("username",username,1);
/跳转到ex8html页面/
documentlocation = "bhtm";
} else {
alert("用户名或密码错误!");
}
}
function $(id) {
return documentgetElementById(id);
}
</script>
</head>
<body>
<div id="main">
<div><span>用户名:</span><input type="text" id="user" /></div>
<div><span>密码:</span><input type="password" id="pass" /></div>
<div>
<input type="checkbox" id="save" />
7天内无需登录
<input type="button" onclick="login()" value="登录" />
</div>
</div>
</body>
</html>
b页面
<html><head>
<title>b</title>
<script type="text/javascript">
/
读取指定的Cookie值
@param {string} cookieName Cookie名称
/
function ReadCookie(cookieName) {
var theCookie = "" + documentcookie;
var ind = theCookieindexOf(cookieName);
if(ind==-1 || cookieName=="") return "";
var ind1 = theCookieindexOf(';',ind);
if(ind1==-1) ind1 = theCookielength;
/读取Cookie值/
return unescape(theCookiesubstring(ind+cookieNamelength+1,ind1));
}
function $(id) {
return documentgetElementById(id);
}
function init() {
var username = ReadCookie("username");
if(username && usernamelength>0) {
$("msg")innerHTML = "<h1>欢迎光临," + username + "!</h1>";
} else {
$("msg")innerHTML = "<a href='ahtm'>请登录</a>";
}
}
</script>
</head>
<body onload="init()">
<div id="msg"></div>
</body>
</html>
效果如下:
你需要从B页面将参数再传到C中去。
如:
A页面:Bactionp1=1&p2=2,跳转到B页面。
B页面中的子页面为<iframe src="Cactionp1=<s:property value='p1'/>&p2=<s:property value='p2'/>">。
那么,在C页面就可以拿到参数值了。
假设这JSP叫 indexjsp,自己提交给自己
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<body>
<form id="test" method="post" action="indexjsp">
<select id="code" name="plugin">
<option value="1cn">cn</option>
<option value="2us">us</option>
<option value="3en">en</option>
</select>
<input type="submit" value="提交">
<br>
<%outprintln(requestgetParameter("plugin")); %>
</form>
</body>
</html>
请采纳
1、首先在电脑打开eclipse软件。然后创建int参数age,赋值为21。代码:int age=21。
2、参见静态方法addAge(int a),内有参数a。
3、然后在addAge方法中,增加a增值的代码。
4、然后再从addAge方法中,输出a增加后的值。
5、然后在main方法中,将age的值传递给a。
6、然后在main方法中,输出数值传递之后的效果。
那得看你是用的什么方式传递的参数,我只能是把所有的传参和获取方法列出来,具体是那个你自己看把。
在之前假设第一个页面为sendaspx,第二个页面为receiveaspx
1、通过URL链接地址传递
(1) sendasp代码
protected void Button1_Click(object sender, EventArgs e)
{
RequestRedirect("Default2aspxusername=honge");
}
(2) receiveaspx代码
string username = RequestQueryString["username"];//这样可以得到参数值。
2、POST方式传递
(1) sendasp代码
<form id="form1" runat="server" action="receiveaspx" method=post>
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="username" runat="server"></asp:TextBox>
</div>
</form>
(2) receiveaspx代码
string username = RuquestForm["receive"];
3、Session方式传递
(1) sendasp代码
protected void Button1_Click(object sender, EventArgs e)
{
Session["username"] = "honge";
RequestRedirect("Default2aspx");
}
(2) receiveaspx代码
string username = Session["username"];//这样可以得到参数值。
4、Application方式传递
(1) sendasp代码
protected void Button1_Click(object sender, EventArgs e)
{
Application["username"] = "honge";
RequestRedirect("Default2aspx");
}
(2) receiveaspx代码
string username = Application["username"];这样可以得到参数值。
5、使用ServerTransfer进行传递
(1) sendasp代码
public string Name
{
get {
return "honge";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ServerTransfer("Default2aspx");
}
(2) receiveaspx代码
send d = ContextHandler as send ;
if (d != null)
{
ResponseWrite(dName);//这样可以得到参数值。
}
以上就是关于structs2:action如何从页面获取参数值以及如何向页面传出参数值(set方法 、get方法、getParameters()方法全部的内容,包括:structs2:action如何从页面获取参数值以及如何向页面传出参数值(set方法 、get方法、getParameters()方法、两个html页面之间怎么传递参数值、A页面请求action,跳转到B页面,想在B下面的子页面获取参数,如何处理。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)