is This possible - request.getParameter(xx);

Hi,

I got a parameter which changes all the time (in my jsp) as follows

e.gparam1_12-1_value and next time it will be param1_13-2_value

the middle part changes

I have a request.getParameter("xxxx"); in my server side code.

Is it possible to have regular expression for xxxx?

What is the best way to handle this.

The parameter got a patern, hence I thought should be handled by regular expression.

Waiting for a reply

[473 byte] By [lalith123a] at [2007-11-27 11:37:24]
# 1

hi,

<%

int j=1;

for ( int i =startingvalue; i < = endingvalue ; i++ )

{

out.println ( request.getParameter ("param1_"+ i +"-"+ j++ +"_value" ) );

}

%>

drvijayy2k2a at 2007-7-29 17:14:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You can use HttpServletRequest#getParameterNames() to retrieve all parameter names. Just loop through those names and look for matches. You can use String#matches() with regexp, but if the prefix and suffix of the name are always identical, then you can also consider String#startsWith() and String#endsWith(), which are slightly faster than using regexps.

BalusCa at 2007-7-29 17:14:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi,

I know all of these are possible, but I thought without introducing for loops or iterators whether it is possible to get it first time by use of a reqx expression,

This is a very common requirement, I do not like to loop through unnecessarily.

Thanks,

lalith123a at 2007-7-29 17:14:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

If it is common, just write an utility method for that.

BalusCa at 2007-7-29 17:14:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...