• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display Database query in JSP?

 
Jane Skylar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jane Skylar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic