asp.net Request.Param 用法

來源:互聯網
上載者:User

Request.Params 是在 QueryString、Form、Server Variable 以及 Cookies 找資料, 他首先在 QueryString 集合尋找資料,如果在 QueryString 找到資料,就返回資料,如果沒有找到就去 Form 集合中尋找資料,找到就返回,否則在往下一下個集合尋找資料。

執行個體

 代碼如下 複製代碼

Main HTML

function jumpToPage(obj)
{ var url = obj.options[obj.selectedIndex].value; if
(url != "none") { parent.frames
["contentframe"].location = url; }
}

<select name="select" onchange="javascript:jumpToPage
(this)" class="DropDownMenu" ID="Select1">

<option value="simplepage.aspx?rptid=<%# "Test"%
>">Report1</option>
</select>


//This is the SimplePage.apsx

<%@ Register TagPrefix="CrystalReports"
Namespace="CrystalDecisions.Web"
Assembly="CrystalDecisions.Web, Version=9.1.5000.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

<@ Page Src="SimplePage.cs"
Inherits="CRSamples.SimplePage" %

<form method="POST" runat="server" > Test Reports
<CrystalReports:CrystalReportViewer
id="CrystalReportViewer1" runat="server" width="350px"
height="50px" pagetotreeratio="4" borderstyle="Dotted"
borderwidth="1px"/> </asp:button

\This is the SimplePage.cs
using System;
using System.Web;
using Microsoft.Win32;


namespace CRSamples
{
public class SimplePage : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer
CrystalReportViewer1;

protected void Page_Init(object sender, EventArgs e)
{
Uri MyUrl = Request.Url;
string rptid=Request.Params.Get("rptid");
Response.Write(rptid);
}
}
}


Request.Params["id"] ,Request.Form["id"] ,Request.QueryString["id"] 的用法以及區別?
Request.Params是所有post和get傳過來的值的集合,Request.Form是取post傳值, Request.QueryString是get傳過來的值


執行個體

 代碼如下 複製代碼

package com.ehi.struts.interceptor.servicemanagement;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.opensymphony.xwork2.ActionInvocation;
import org.apache.commons.lang.StringUtils;

/**
* An interceptor to trim all the parameters. <br>
* It's bascially adapted from the book, <br/>
* 'Apache Struts 2 Web Application Development'
*
* @author candicew
*
*/
@SuppressWarnings("serial")
public class TrimInterceptor extends MethodFilterInterceptor {

private List<String> excluded = new ArrayList<String>();

protected String doIntercept(ActionInvocation invocation) throws Exception {
Map<String, Object> parameters = invocation.getInvocationContext().getParameters();

for (String param : parameters.keySet()) {
if (shouldTrim(param)) {
doTrim(parameters, param);
}
}

return invocation.invoke();
}

void doTrim(Map<String, Object> parameters, String param) {
Object val = parameters.get(param);
if(val == null){
return;
}
if (val instanceof String) {
trimString(parameters, param, val);
} else {
trimStringArray(parameters, param, val);
}
}

private void trimString(Map<String, Object> parameters, String param, Object val) {

String value = (String) val;
value = StringUtils.trimToNull(value);
parameters.put(param, value);

}

private void trimStringArray(Map<String, Object> parameters, String param, Object val) {

String[] vals = (String[]) val;
boolean allNull = true;
for (int i = 0; i < vals.length; i++) {
vals[i] = StringUtils.trimToNull(vals[i]);
allNull = allNull && (vals[i] == null);
}
if (allNull) {
parameters.put(param, null);
}

}

private boolean shouldTrim(String param) {
for (String exclude : excluded) {
if (param.equalsIgnoreCase(exclude)) {
return false;
}
}

return true;
}

public void setExcludedParams(String excludedParams) {
for (String s : StringUtils.split(excludedParams, ",")) {
excluded.add(s.trim());
}
}

}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.