I have n number of text fields named in the form "Question.....". How can I get all the parameters which starts with "question" from the JSP page to the Action?
+2
A:
This should print out all Parameters that start with "Question".
<html><body>
<%@ page import = "java.util.*" %>
<b>Parameters:</b><br>
<%
Enumeration parameterList = request.getParameterNames();
while( parameterList.hasMoreElements() )
{
String sName = parameterList.nextElement().toString();
if(sName.toLowerCase.startsWith("question")){
String[] sMultiple = request.getParameterValues( sName );
if( 1 >= sMultiple.length )
// parameter has a single value. print it.
out.println( sName + " = " + request.getParameter( sName ) + "<br>" );
else
for( int i=0; i<sMultiple.length; i++ )
// if a paramater contains multiple values, print all of them
out.println( sName + "[" + i + "] = " + sMultiple[i] + "<br>" );
}
}
%>
</body></html>
lajuette
2010-04-02 06:08:45
+6
A:
<%@ page import = "java.util.Map" %>
Map<String, String[]> parameters = request.getParameterMap();
for(String parameter : parameters.keySet()) {
if(parameter.toLowerCase().startsWith("question")) {
String[] values = parameters.get(parameter);
//your code here
}
}
Finbarr
2010-04-07 19:26:39