reading paramaters from a url string
hi there,
Im trying to read some parameters from a url:
I go to http://somewhereonline.com/applet.html?val1=somevalue
how do I read val1 in my applet? Can I just do this:
String value = getParameter("val1");
If so, it doesnt seem to be working for me...Ive seen some pretty complicated applets that do what I want through javascript and I cant say I really understand them...is there a simple way to do what I want and stick with just the applet code embedded in html?
Thx in advance,
nick
halfhp@dsldesigns.net
[587 byte] By [
halfhp] at [2007-9-26 2:58:35]

From the api-docu:
Returns the value of the named parameter in the HTML tag. For example, if this applet is specified as
<applet code="Clock" width=50 height=50>
<param name=Color value="blue">
</applet>
then a call to getParameter("Color") returns the value "blue".
So, no, you can't use this method to get the value of an URL parameter
Hi, thx...
So how do I do it?
I know that the getParameter() method is used in some form or another - the examples I have seen have all been accompanied by some confusing javascript though so their design escapes me...
Any and all suggestions / solutions are most appreciated.
Thx,
Nick Fellows
halfhp@dsldesigns.net
halfhp at 2007-6-29 10:53:41 >

if your url is in the form of a java.net.URL object, you can use the getQuery() method to return the query part (ie the part after the '?')
so for example, if your URL is http://localhost:8080/index.htm?param1=val1¶m2=val2
then getQuery() will return:
param1=val1¶m2=val2
You could then use StringTokenizer to get the name/value pairs by splitting it up at the '&' characters. I'll assume you put these in a String array called pairs[]
Finally, you can define your own getParameter method to search thru your string array of pairs:public String getParameter(String param){
for (int j=0;j<pairs.length;j++){
if (pairs[j].indexOf(param)=0){
return pair.substring(pair.indexOf('=')+1);
}
}
}
'>
Hey bud,Thx for the info.How would I get the URL object? I havnt been able to find a method to return the URL string that called the applet yet. Thx,Nick Fellowshalfhp@dsldesigns.net
halfhp at 2007-6-29 10:53:41 >

> Hey bud,> Thx for the info.> How would I get the URL object? I havnt been able to> find a method to return the URL string that called the> applet yet.Her's how to get the url:java.net.URL url = getDocumentBase();
sorry - "Here's", not "her's" - Edward SausageHands strikes again :-)
Hey bud,
Thx again for the info.
Only problem I have with getDocumentBase() is that it doesnt return any of the parameters passed through the URL that the user types into the browser, just the absolute path to the location of the applet.
Is there a way to get the entire string of URL text from the browser?
Thx again,
Nick Fellows
halfhp@dsldesigns.net
halfhp at 2007-6-29 10:53:41 >

That's strange, since I tried it out before I posted it and it worked OK for me. A question: have you actually tested it with a user requesting your applet from a web-server (using http://www.... etc), or have you only tested it locally on your machine (by double-clicking the html file etc)?
(I tested it using Tomcat as a web server and it worked OK)