Closed Thread Icon

Topic awaiting preservation: setting variables (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22096" title="Pages that link to Topic awaiting preservation: setting variables (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: setting variables <span class="small">(Page 1 of 1)</span>\

 
EDDII
Nervous Wreck (II) Inmate

From:
Insane since: May 2004

posted posted 06-08-2004 17:17

yo on some pages they have address.jsp?varient=hi is this for setting variables on the pages that could be picked up by javascript or what i would like to know can anybody help?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-08-2004 17:27

jsp are Java Server Pages - and since javascript doesn't have anything to do with Java...

I don't know enough about Java Server Pages to ascertain wether the parameters passed via GET (ie. ?something=something after the url) are turned into variables, but somehow I doubt it. It's a lot more likely they're stored into an associative array or such.

So long,

Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 06-08-2004 20:53

You can get the parameters (GET or POST) in the JSP (Java code) using the following:

code:
<%
String var = request.getParameter("varient");
....
%>



You can parse only GET URLs in the client side code (window.location.href).
Try the following code to parse URL (I'm sure you can improve it)

code:
//<protocol>://<user>:<password>@<server>:<port>/<URI>?<param1>=<val1>&<param2>=<val2>&<param3>=<val3>
var _COMP_ERR = "***ERROR***"
function parseURL(url){
// Build the return URL object.
var oUrl = new Object();
oUrl.uri = "";
oUrl.port = 80;
oUrl.protocol = "http";
oUrl.server = "";
oUrl.user = "";
oUrl.password = "";
oUrl.parameters = new Array();

// Get the protocol (if any) <protocol>://...
var tmp = trim(url);
var i = tmp.indexOf("://");
if(i>-1){
oUrl.protocol = tmp.substring(0, i).toLowerCase();
tmp = tmp.substring(i + 3, tmp.length);
}

// get the URI <user>:<password>@<server>:<port>/<URI>?....
i = tmp.indexOf("?");
var uri = tmp;
if(i>-1){
uri = tmp.substring(0, i);
tmp = tmp.substring(i + 1, tmp.length);
} else {
tmp = "";
}
// get authentication user & password (if any) <user>:<password>@
i = uri.indexOf("@");
var auth = "";
if(i>-1){
auth = uri.substring(0, i);
uri = uri.substring(i + 1, uri.length);

i = auth.indexOf(":");
oUrl.user = auth;
if(i>-1){
oUrl.user = auth.substring(0, i);
oUrl.password = auth.substring(i + 1, auth.length);
}
}
// get the server name and port <server>:<port>/...
i = uri.indexOf("/");
var server = uri;
if(i>-1){
server = uri.substring(0, i);
try {
oUrl.uri = decodeURI(uri.substring(i + 1, uri.length));
}catch(e){
oUrl.uri = _COMP_ERR;
}
}
oUrl.server = server;
i = server.indexOf(":");
if(i>-1){
oUrl.server = server.substring(0, i);
oUrl.port = server.substring(i + 1, server.length);
try {
oUrl.port = parseInt(oUrl.port);
}catch(e){
oUrl.port = _COMP_ERR;
}
}

// get the parameters ?<param1>=<val1>&<param2>=<val2>&<param3>=<val3>...
while(tmp.length>0){
var oParam = new Object();
var param = "";
i = tmp.indexOf("&");
if(i>-1){
param = tmp.substring(0, i);
tmp = tmp.substring(i + 1, tmp.length);
} else {
param = tmp;
tmp = "";
}

i = param.indexOf("=");
if(i>-1){
oParam.key = param.substring(0, i);
try {
oParam.value = decodeURIComponent(param.substring(i + 1, param.length));
}catch(e){
oParam.value = _COMP_ERR;
}
} else {
oParam.key = param;
oParam.value = "";
}
if(oParam.key.length > 0){
oUrl.parameters[oUrl.parameters.length] = oParam;
}
}

return oUrl;
}

EDDII
Bipolar (III) Inmate

From:
Insane since: May 2004

posted posted 06-09-2004 14:06

well i have actually seen it on all extesions .php .htm.jsp and so on and if it isnt so that the variable can be picked up by javascript does anybody know how it works?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-09-2004 15:04

come in again, I couldn't understand one sentences.

Actually, you only used one sentence, and it doesn't make any sense.
English might not be your first language, but a certain level of puncuation, and subject-predicat-object, coupled with appropriate verbs goes a looooooong way.

EDDII
Bipolar (III) Inmate

From:
Insane since: May 2004

posted posted 06-09-2004 15:57

whatever man i dont understand punc-tu-a-tion what i asked was does anybody know why you would put ?somthing=somthing after the file exstension

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-09-2004 16:00

simply to pass a variable in GET. That way it's accessible to both server-side and client-side languages, and the experienced end user can change the values by hand in the address bar.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-09-2004 16:20

ah, one would do that because one understands punctuation.

To be a little more accurate (than poi), ?key=value is being used to pass a parameter with a HTTP GET request, as defined by RFC 2616, Section 3.2.2 ('http URL').

It should be used to tell the server to retreive more or less 'static', bookmarkable information. (As oppossed to passing parameters via HTTP Post and one of it's encodings)

you know, if your question read 'what are those ?key=value things in urls for?' or 'can anyone explain whatfor'... (instead of 'can anybody help' - this suggest you're having a problem, not simply a want for information), you'd have gotten an answer at your level right away, instead of about 2 pages worth of details which you don't seem to have understood.

so long,

->Tyberius Prime

« BackwardsOnwards »

Show Forum Drop Down Menu