General discussion

Locked

Java servlets

By jcsmith_pgh ·
I am beginning to use servlets through an Apache web server. I understand how the servlet interacts with the posts from the web page users overall, but I am not sure of how to handle multiple selection boxes. How do you receive all of the responses from the post for the multiple selections? How do they come through? (As comma seperated with the variable name listed once, or as seperate entries with the same variable name) Any help is appreciated.

Jeremy

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Java servlets

by jcsmith_pgh In reply to Java servlets

Point value changed by question poster.

Collapse -

Java servlets

by Rakesh Goenka In reply to Java servlets

The response from multiple selections (as in a multi-select list), will be name=<value1>&name=<value2>&name=<value3>
as in
accounts=1&accounts=2&accounts=3

The HTTPRequest object has a getParameterValues() method which allows to get the multiple values by supplying the name. Here is a code example where I get multiple account selections for a report and convert them into a long[]:

....
String[] accounts = request.getParameterValues( "accounts" );
long[] accountIDs = null;
if ( accounts != null ) {
int count = accounts.length;
accountIDs = new long[ count ];
for ( int i = 0; i < count; i++ ) {
accountIDs = Long.parseLong( accounts );
}

// work with account ids further
....

I have found an issue where I was using multi-select by using same name for checkboxes, but a few browsers only returned the first selection of the check box. A multi-selection list is compatible with all browsers.

Hope that helps,

Collapse -

Java servlets

by jcsmith_pgh In reply to Java servlets

Poster rated this answer

Collapse -

Java servlets

by jcsmith_pgh In reply to Java servlets

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums