jeudi 22 avril 2021

How to create a Select tag dynamically in jsp?

Well i have created a select tag in my jsp form , for which i would want to dynamically retreive data from mysql database and show in the jsp page select tag:

The basic code of jsp select tag :

  <label for="course">Ward No:</label>
                                    <div class="form-select">
                                <select name="Ward" id="course">
                                    <option value="0">--Select Ward No---</option>
                                    <option value="ward1">1</option>
                                    <option value="ward2">2</option>
                                    <option value="ward3">3</option>
                                    <option value="ward4">4</option>
                                    <option value="ward5">5</option>
                                    <option value="ward6">6</option>
                                    <option value="ward7">7</option>
                                    <option value="ward8">8</option>
                                    <option value="ward9">9</option>
                                    <option value="ward10">10</option>
                                    <option value="ward11">11</option>
                                    <option value="ward12">12</option>
                                </select>

From which i would want to as above display numbers from 1 to 12 however if an entry inside the database has a number for database table column 'wardNo' I would want my jsp not to show it .

And only show the numbers except the one already there . Ex: if db table column has 12 then jsp form select tag must display 1 to 11 .

However I am stuck of finding the best way to achieve this , is it better to use array list in MVC model to achieve this or would it be better to do it all in jsp ? Whats the best way to do this ?

I am currently learning java development so please excuse any mistakes or not being the best at following best pratices.

Thanks for all in advance for helping me out.




Aucun commentaire:

Enregistrer un commentaire