简体   繁体   中英

How do I get the attributes of a tag?

Been looking everywhere, I just can't seen to find it (probably because I'm wording it wrong or something).

In have a simple select tag in a from with several options. Each option has an id attribute. I want to get the id from the selected options.

The name of the select tag is "group", so in the servlet I call:

String group = request.getParameter("group");

This only returns the "label" of the option (the name of it, what the user sees). I don't want that, I want the id of it. I tried

String group = request.getParameterValues("group");

but that just returns an array with one item, the label of the option.

How can I do this? Thanks.

You should set the value attribute of the option tag to what you want to get from servlet:

   <select name="parent">
     <c:forEach items="${parents}" var="parent">
       //      here set value="yourid"
       <option value="${parent.id}">${parent.name}
     </c:forEach>
   </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM