I want to populate a combo box with the dates which i would do by invoking a servlet. My questions are:
1) How can i load a servlet as soon as the Jsp page loads as former would pick up values from database and add one more date each day to db.
2) How can i add the option tag dynamically as there would be hundred's of them which would obviously keep on increasing, as each day there would be an increase in the option tag (as the combo box shall contain the dates);
I searched a lot but could not find the exact solution to my problem so came to javaranch.
How can i load a servlet as soon as the Jsp page loads as former would pick up values from database and add one more date each day to db.
1. If you dont have any data from the Jsp while calling the servlet:
Then you can directly call the JSP from the Servlet, do whatever you want with db in that servlet itself and send those results to the jsps as attributes.
I got the solution for my first question but solution to 2nd one is still pending. As one just add the <option> tag in select tag add an entry to the combo box. I want the value that is returned to the jsp as a array list which inturn contains dates to be displayed in the combo box. Now how could i generate the <option> tags equal to the length of the array list and display each array list values.
I'm not sure what you mean by 'load a servlet as soon as the jsp loads'. If you're using a servlet as a controller, it should instanciate whatever class fetches the information from the database (dates or anything else), and bind that data to scope. It should then forward context to your JSP which can loop through the data structure to build the option tags for your select list.
This is pretty standard. Maybe I'm not understanding your question.
I want the value that is returned to the jsp as a array list which inturn contains dates to be displayed in the combo box. Now how could i generate the <option> tags equal to the length of the array list and display each array list values.
That is pretty simple. In your <select> tag (ComboBox), Iterate the arraylist which you have in the Jsp and just insert the <option> tag in the arraylist iterate loop.
Thanks for reply. Actually the question i have asked is really pretty standard as i am new to developing webapp.
I implemented tha approach you just told and successfully created the dropdown list (read the link you provided). Thanks for the answer.
One more thing regarding I'm not sure what you mean by 'load a servlet as soon as the jsp loads'.
Actually i was thinking if it is possible to load a servlet, when a jsp page is loaded i.e if the jsp page is the first page of the website & one have to fetch values from the database which would be displayed on that page then i would like to call the servlet as soon as one hits the url(or when the jsp page loads) eg. javaranch.com and the servlet would return the values to the welcome page or the first page. How would i invoke the servlet as soon as the jsp loads so that the values from database be displayed on that first page.