This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes How to display Database query in JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "How to display Database query in JSP?" Watch "How to display Database query in JSP?" New topic
Author

How to display Database query in JSP?

Jane Skylar
Greenhorn

Joined: Nov 24, 2011
Posts: 3
Hey guys I'm pretty much lost as to what to do.

I have configured my DB and am using hibernate, I wrote a successful query




I have also configured a browser file with the hibernate query.




Now what I want to do is display the whole table in JSP when a user selects 10 as the course credit hours

I have no idea how to do that, all I have is this.



How would I write this , any suggestions??
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
Iterate over the course list and print out properties for each item:



But writing such code in a JSP is not recommended. You should use the tag <iterate> in the JSTL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Get the information in the servlet page controller for the JSP and then use there JSTL and EL to create the HTML for display.

Putting Java code in a JSP is a poor practice that has been discredited for almost 10 years.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jane Skylar
Greenhorn

Joined: Nov 24, 2011
Posts: 3
Bear Bibeault wrote:Get the information in the servlet page controller for the JSP and then use there JSTL and EL to create the HTML for display.

Putting Java code in a JSP is a poor practice that has been discredited for almost 10 years.


I did as you have suggested and added spring framework MVC. I am using a controller class now.

I can display the data just fine but so far I only know one operation a query.





How do I expand this so I can insert and delete records into the database?

and How do I say pass variables into this controller from a JSP page lets say a user clicks a button (delete)

and it passes the action of deleting a specific entry to the controller preforms the delete and updates the database?
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
Jane Skylar wrote:
I did as you have suggested and added spring framework MVC. I am using a controller class now.


Seems you are going on the right track.


Jane Skylar wrote:
How do I expand this so I can insert and delete records into the database?

Which context does the question imply? Hibernate or Spring MVC?


Jane Skylar wrote:
and How do I say pass variables into this controller from a JSP page lets say a user clicks a button (delete)


Use Spring's form tag in the JSP page and use the @ModelAttribute in the Spring action's method with a proper form bean object.


Jane Skylar wrote:
and it passes the action of deleting a specific entry to the controller preforms the delete and updates the database?



Just creating other action methods that do the jobs of delete and update.
 
GeeCON Prague 2014
 
subject: How to display Database query in JSP?