Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting database data to the UI  RSS feed

 
michael delta
Ranch Hand
Posts: 35
Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,I have the following code:
(I'm quoting only the important stuff)



The problem is I want to print the photoname String in a h2 heading(and a lo) afterwards. How is that possible?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the code put of a JSP and into a Java class. Java code has no place in modern JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've moved the code to a servlet controller (and really the JDBC code should be even further removed to a model layer), capture the data from the result set into a bean or other Java construct and pass it to the JSP as a scoped variable. Forward to the JSP from the controller.

In the JSP, use the EL to emit the value.

For example, let's say the that data is capture in a scoped variable bean named myBean in a property named photoName. In the JSP:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the concept of controllers is new to you, please see this article.
 
michael delta
Ranch Hand
Posts: 35
Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!