Java Netbeans and HTML
I am developing a web application using HTML and Netbeans. I have the database connection set up between MySQL and Netbeans but the output is not printing on the HTML pages as of yet i.e. it is only printing in Netbeans.
On one of the HTML pages there is a drop down box. I want to populate this drop down box with data from the MySQL database but I can't figure out how. Once the user selects an item from the drop down box then the text boxes on the HTML should also be populated with the corresponding data in the database.
Would really appreciate some help!
You can use a browser, or preview in netbeans!
I have heard that a PHP script inserted into HTML code will be useful and something called DB control language may be used.
real post is under this one, accidently hit enter:p
in your program, you should read all the needed files from ur DB , and create a bean class for them.So u can create an object for every record in your DB.That way you can keep an array of objects as the representation for your DB.You can access every record that way.
good luck with it.
you developed front end in html or jsp(better use jsp)---->servlet----->database.
So, servlet makes connection to database and pull out records. So, data is still in servlet until now.
session.setAttribute("session variable",data pulled from db); to store data in session variable. Once you store in session variable.
go to jsp where where your combo box is.
in the option tag of combo box you can do: <%=request.getAttribute("session variable")%>
you should be getting the value in combo box.
Do import the java servlet class in ur jsp page using page directive.
Hope this helps.
Not in the session.
No no no.
You should store as little as possible in the session, and definitely not store stuff that is clearly request scoped stuff...
@Aseem: Wouldnt you get data acces and bean classes between your servlet and database?
It's not very nice to combine data acces methods with businiss logic and basic entitities in one class.Seems logical to me that you create objects of the records in your database.
@Tolls: Where do you suggest storing the records then?
You only need them to display them on a page...so they go in the request.
i assume since you are using combo box, there wont be many data. So session was suggested. Yes, you can use bean.
Using this technique to pass beans, a request dispatcher (using either “include” or forward ” ) can be called. This bean will disappear after processing this request has been completed.
Servlet: request.setAttribute( “theBean”, myBean );
RequestDispatcher rd = getServletContext( ).getRequestDispatcher( “Thepage.jsp” );
< jsp: useBean id="theBean" scope="request" class="....." />
Sticking stuff in the session is a bad habit to get into. It doesn't scale.
agreed with trolls.
I know how to code a jsp page aseem , but thx for the explanation anywayz ^^