Asp.net Request. Param usage

Source: Internet
Author: User
Tags trim

Request. params searches for data in QueryString, Form, Server Variable, and Cookies. It first searches for data in the QueryString set. If the data is found in QueryString, the data is returned, if no data is found, search for data in the Form set. If no data is found, return. Otherwise, search for data in the next set.

Instance

The code is as follows: Copy code

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"] usage and difference?
Request. Params is a collection of all post and get values. Request. Form is the post value, and Request. QueryString is the get value.


Instance

The code is as follows: Copy code

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. Fig (exclude )){
Return false;
}
}

Return true;
}

Public void setExcludedParams (String excludedParams ){
For (String s: StringUtils. split (excludedParams ,",")){
Excluded. add (s. trim ());
}
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.