Pass HTML dropdown value to JSTL sql:query

大兔子大兔子 提交于 2020-01-14 04:31:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!