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));
 %>
Alice
  • 117
  • 5
  • 16

1 Answers1

0

If you defined your combo box like this:

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

When the user submits the form, the browser sends the selected option value as a GET or a POST parameter (depending on the form's action method) choose.

In the JSP which processes the request you can use the predefined variable request to extract the parameter:

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

Warning Please don't use string concatenation to build your SQL. This can lead to a security hole. See SQL injection. Use a prepared statement instead to escape the user input.

vanje
  • 10,180
  • 2
  • 31
  • 47