java 获取选定的值下拉jstl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13875117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the selected value dropdown jstl
提问by Bruno Andrade
With this drop down I'll select a value and pass in a url, but with this code i'm not able to get only the selected one, can you guys help me to setup a c:if and mark selected on the side?. Thanks anyway.
使用此下拉菜单,我将选择一个值并传入一个 url,但是使用此代码我无法仅获取选定的值,你们能帮我设置 ac:if 并在侧面标记 selected 吗?不管怎么说,还是要谢谢你。
<select>
<c:forEach var="foo" items="${bar}">
<option value="${foo}">${foo}</option>
</c:forEach></select>
<div class="links" style="font-size: 110%">
<a href="someURL?path=${foo}">someName</a>
</div>
Ex:
前任:
<select>
<c:forEach var="name" items="${names}">
<option value="${name}">${name}</option>
</c:forEach></select>
After i select the name, place the selected one in the url
选择名称后,将所选名称放在 url 中
<div class="links" style="font-size: 110%">
<a href="someURL?path=${name}">someName</a>
</div>
Sorry, my english isn't that good so it's hard sometimes to express myself
对不起,我的英语不是很好,所以有时很难表达自己
回答by JB Nizet
<option value="${foo}"
<c:if test="${param.path == foo}">selected="selected"</c:if>>${foo}</option>
Read http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html
阅读http://docs.oracle.com/javaee/1.4/tutorial/doc/JSIntro7.html
回答by zhangy
u can use javascript traversal to get selected value,if u do not use this ,u can use request.setAttribute("","") to set value ,<%= request.getAttribute("","")%> to get value , <% for(){}%> ,javascript to get selected value.
你可以使用javascript遍历来获取选定的值,如果你不使用它,你可以使用 request.setAttribute("","") 来设置值,<%= request.getAttribute("","")%> 到get value , <% for(){}%> ,javascript 获取选定值。