将HTML下拉值传递给JSTL sql:query [英] Pass HTML dropdown value to JSTL sql:query

查看:148
本文介绍了将HTML下拉值传递给JSTL sql:query的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML下拉菜单,我想将所选值作为参数传递给SQL查询。

I have a HTML dropdown menu where I want to pass the selected values as parameter to the SQL Query.

这是下拉列表:

<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>

这是我的查询

<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>

我想从下拉列表中传递参数value

I want to pass the parameter from the dropdown "value"

<c:set var="hub" value="value of the dropdown"/>

这样我就可以将它作为查询的参数其中img_hub = ?

So that I can use it as parameter to my query "where img_hub = ?".

推荐答案

它可以作为 $ {param的请求参数} 以通常的方式映射确切名称,因为您已经给出了< select> 元素。

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.

所以给定

<select name="ifs_db_options">

你可以在EL中得到如下信息

you can get it as follows in EL

${param.ifs_db_options}

请注意对于正常的生产应用程序,JSTL SQL taglib是气馁,因为它严重紧张-couples代码。

Please note that the JSTL SQL taglib is discouraged for normal production apps as it heavily tight-couples the code.

这篇关于将HTML下拉值传递给JSTL sql:query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆