问题
I have a HTML dropdown menu where I want to pass the selected values as parameter to the SQL Query.
this is the Dropdown:
<select name="ifs_db_options" onchange="submit()">
<c:forEach var="ifs_db1" items="${ifs_db1.rows}">
<option value="${ifs_db1.rows}" selected>${ifs_db1.img_hub}</option>
</c:forEach>
</select>
And this is the my query
<c:set var="hub" value="${ifs_db1}"/>
<sql:query var="ifs_db" dataSource="jdbc/postgresDB">
select * from ifs_db where img_hub = ?
<sql:param value="${hub}" />
</sql:query>
I want to pass the parameter from the dropdown "value"
<c:set var="hub" value="value of the dropdown"/>
So that I can use it as parameter to my query "where img_hub = ?"
.
回答1:
It's available as request parameter by ${param}
map the usual way with as key the exact name as you've given the <select>
element.
So given
<select name="ifs_db_options">
you can get it as follows in EL
${param.ifs_db_options}
Please note that the JSTL SQL taglib is discouraged for normal production apps as it heavily tight-couples the code.
来源:https://stackoverflow.com/questions/9397832/pass-html-dropdown-value-to-jstl-sqlquery