一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net Request.Param 用法

时间:2011-10-18 编辑:简简单单 来源:一聚教程网

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; }
}


//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" %

Test Reports
id="CrystalReportViewer1" runat="server" width="350px"
height="50px" pagetotreeratio="4" borderstyle="Dotted"
borderwidth="1px"/>

\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.

* It's bascially adapted from the book,

* 'Apache Struts 2 Web Application Development'
*
* @author candicew
*
*/
@SuppressWarnings("serial")
public class TrimInterceptor extends MethodFilterInterceptor {

private List excluded = new ArrayList();

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

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

return invocation.invoke();
}

void doTrim(Map 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 parameters, String param, Object val) {

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

}

private void trimStringArray(Map 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());
}
}

}

热门栏目