I am new to this world.
I wrote an application that has a dropdown list and I need data from database to be populated in that dropdown before submitting and adding the data to another table.
Please help me in getting this done through beans or JSP.
Thank you all..
Joined: Jan 11, 2009
Store the data in hashmap or in an array list and iterate it for example use as in this way
Bean instance = (Instance of bean)arraylist.get(i);
//Store all the values in the bean and now close the scriptlet
//Put the code for select box like
<option value= <%=bean instance.get id %><%=bean intance.get required value&>
Hope you have understood
Joined: Aug 19, 2009
i am very new to this, so to be honest I dont understand,.
Let me put what i have done so far..
In my Class file
First off, since you are new to JSP, it's important to establish good habits right up front. Rule #1 is to never, never, never, put Java code ina JSP. Never. That's a really old-fashioned and bad practice.
Rather, you should fetch the data from the DB in a servlet controller, or a bean, to use on the JSP.
Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.
Gudim, Just above your post Bear mentioned that don't use Java code(Scriptlets) in JSP. JSTL and EL better alternatives.
Joined: Nov 06, 2000
Vishal Pandya wrote:Gudim, Just above your post Bear mentioned that don't use Java code(Scriptlets) in JSP. JSTL and EL better alternatives.
I agree. Your JSP would be structured something like this:
This code assumes that some previous code, such as your MVC controller, placed a java.util.List in scope -- e.g., via request.setAttribute("mylist",aList); -- and also assumes that each list item has a "getProperty()" method.
To learn more, Google "JSP expression language" and "jstl".
Joined: Apr 01, 2003
The Java Bean ( DTO ) is as follows:
The Java Bean ( DAO ) is as follows.
JSP accessing the DAO class is as follows.
The database ( test ) is updated with state names in a table ( states ) .
Joined: May 20, 2008
In the code sample provided by Sunder Ganapathy for the dropdown, is there a posibility to pass locale from jsp to the DAO?
My database table is setup for different locales and I am currently working with something like this: ("select * FROM tablename WHERE tablename.locale='en_CA'")
I need the locale to change when user switches language. I am thinking of keeping locale in a session variable but not sure if it would be a good practice to specify session variable in the WHERE clause. Are there other better options?