--- On Tue, 8/5/08, David Wall <[EMAIL PROTECTED]> wrote:

> From: David Wall <[EMAIL PROTECTED]>
> Subject: Re: Parsing a URL to see if a param exists
> To: "Tomcat Users List" <users@tomcat.apache.org>
> Date: Tuesday, August 5, 2008, 7:50 PM
> >
> http://java.sun.com/docs/books/tutorial/networking/urls/urlInfo.html
> >
> > It breaks down every component of the url (protocol,
> domain name, etc).  Is that what you're looking for?
> >   
> 
> Not really since I just need to process the query string
> portion to see 
> if a given param exists or not.  I'm using a simple
> homegrown parser now:
> 
>     public boolean isParamInUrl(String url, String
> paramName)
>     {
>         int pos = url.indexOf("?");
>         if ( pos > 0 )
>             url = url.substring(pos);
>         String[] paramValues =
> url.split("&");
>         if ( paramValues == null )
>             return false;
>        
>         for( String paramValue : paramValues )
>         {
>             String[] paramAndValue =
> paramValue.split("=");
>             if ( paramAndValue == null ||
> paramAndValue.length != 2 )
>                 return false;
>             if ( paramAndValue[0].equals(paramName) )
>                 return true;
>         }
>         return false;
>     }
> 
> The concern is whether this is valid should the URL have
> complex params 
> and such based on encoding schemes.  I mean, it just splits
> the url 
> query string into an array of param-values '&',
> and then splits that by 
> '=' without concern for any encoding.
> 
> David
> 
> 
Hi,

Wouldn't be faster/less coding if you just use this?

URL aURL = new URL(url);
String urlParams = aURL.getQuery();
if (urlParams.contains(paramName)) {
// proccess as needed if paramName exists
} else {
// process as otherwise
}

just a thought :)

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to