Get URL parameters
ASP
prodid = Request.QueryString ("prodid")
ASP.NET (C#)
string Name = Request.QueryString["Name"];
string Age = Request.QueryString["Age"];
Response.Write(Age);
JSP
String hist_list = "0";
if (request.getQueryString()!=null)
{
hist_list = request.getParameter("hist").trim();
if (hist_list==null)
hist_list="0";
}
JavaScript
A useful little JavaScript function which will get a URL parameter and return it to you.
For example if the current URL is "...?opendocument&id=testid" then calling
getURLParam("id") will return "testid".
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
{
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
{
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}
Redirect
ASP
Response.Redirect "http://www.w3schools.com"
ASP.NET (C#)
protected void Page_Load(Object Src, EventArgs E)
{
Session["login"]=null;
Response.Redirect("index.aspx");
}
JSP
response.sendRedirect("client.jsp");