0

I'm trying to get the selected item from a drop down list (in the same jsp page) and pass it to the WHERE statement in my query but i'm unable to do it successfully, how can I pass the selected item to jsp code?

<%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn3 =   DriverManager.getConnection("jdbc:derby://localhost:1527/Registration", "user", "root");
    Statement statement3 =conn3.createStatement();
    ResultSet rs3 = statement3.executeQuery("select ABSTRACT from App.PAPERSUB2 where PAPERNAME= '"+ "How_TO_GET_THE_SELECTED_ITEM" + "'") ;

     if (rs3.next())
       System.out.println(rs3.getString(1));
 %>
4

1 回答 1

0

如果您像这样定义组合框:

<select id="choose" name="choose">
  <option value="one" >One</option>
  <option value="two">Two</option>
  <option value="three">Three</option>
</select>

当用户提交表单时,浏览器将选择的选项值作为 GET 或 POST 参数发送(取决于表单的操作方法)choose

在处理请求的 JSP 中,您可以使用预定义的变量request来提取参数:

<%
String choosen = request.getParameter("choose");
if(choosen != null) {
%>
Selected value id: <%= choosen %>
<%
}
%>

警告 请不要使用字符串连接来构建您的 SQL。这可能导致安全漏洞。请参阅SQL 注入。使用准备好的语句来转义用户输入。

于 2013-05-19T20:53:39.890 回答