• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamically populate Drop Down list in JSP  RSS feed

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an issue with populating a dropdown list in my HTML form.

I want the form to pull in the values from the Database. I have a connection and I'm able to populate a table with the values.

Now I'm trying to populate a dropdown within a form that will bring in currency codes that are in a column called CURR_CODE from the Database.

I have in bold what I think is kind of on the right track from what I have researched.

Any assistance would be helpful

//Declare variables

//String con_currency_sdo = ""; // as New Connection
String ResultSet = "rs"; // as New Command
String Statement = "stmt"; // as New Recordset
String selBaseCurr = request.getParameter("CURR_CODE");


<script type="text/javascript" src="js/date.js"></script>
function submitCurrency() {
var valid = checkForm(document.currency_form);


<TITLE>Currency Converstion </TITLE>


<h1>Currency Converstion </h1>

<% <!--- Others that I have tried --->
//if(request.getParameter("selBaseCurr") != null){ CURR_CODE = request.getParameter("selBaseCurr"); }
//if(request.getParameter("selTargetCurr") != null){ CURR_CODE = request.getParameter("selTargetCurr"); }

<form action="" method="post" name="currency_form" id="currency_form" ><!--onSubmit="return checkForm(this)"-->
<tr><td>Enter the number of units you want to convert <br>(<i>Note - No commas or other characters are needed or recognized.</i>):</td></tr>
<tr><td><input type="text" name="txtUnits" align="left" size="10" tabindex="1" value="<%=request.getParameter("txtUnits")%>"></td></tr>
<tr><td>Choose the date of the exchange rate you want to use:</td></tr>
<table border="0">

<tr><td>Select the currency you wish to convert:</td></tr>


<select name="selBaseCurr">

<option value=""><%= selBaseCurr%></option>


Author and ninkuma
Posts: 66424
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getParameter() method has nothing to do with the database or with JDBC.

If this is not a JSP from 2001 then you should not have any Java code in the JSP. That's an outdated and obsolete practice from 12 years ago.

You should be getting the list in the controller prior to forwarding to the JSP. Then, in the JSP its a simple matter of iterating over the list with JSTL and EL.

Proper web app structure is the topic of this article.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!