0

I need to populate in my .jsp file selection from database. As you may see, I build the selection using JQuery (I've created the form earlier and now just append things).

I hoped to use something like this:

    <%
    // Connection to DB using JDBC 
    %>
        <script>
        //JS code here
            $form.append('Enter city name: '
                +'<select id="location">' 
                <%
                    for(i=0;i<rowsNum;i++) {
                    out.println("+'<option>"+cities.get(i)+" - "+streets.get(i)+"</option>'");
                }                   
                %>
                +'</select>');
        //JS code here
        </script>
    <%
    //Connection close
    %>

but it doesn't work. A brief search didn't help much.

Is the problem in this particular part of the code, or it's something else and this part is OK?

Thanks!

keshet
  • 1,716
  • 5
  • 27
  • 54

1 Answers1

0

Your code is totally clumsy , why have you combine scriptlets with script . scriptlets are java codes and these are executed on you server . while jquery is the client side java script library .

You can use ajax to get the values from the datebase and populating it in the servlet.

using java codes in jsp is considered as bad practice see this How to avoid Java code in JSP files?

Hope this helps !!

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56