Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why can't I display retrieved data from a mysql database on a webpage properly?  RSS feed

 
thomas lim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How I want my code to work:
User types in a promo id, and data is retrieved from 'promotion' table in mysql according to what the user typed. For example, if user typed 'P01' for promo id, this is how it should look like (this is from a direct mysql query by the way):



The problem:
Data isn't displaying. (Only table headings are displayed)


There are no visible errors when I view my code in Eclipse.

moreinfo.jsp (takes in parameter of promo id; forwards it to PromotionDisplay servlet)



PromotionDisplayServlet



PromotionDisplay.java (object)



PromotionDB.java (takes in object PromotionDisplay)   



displayPromotion.jsp (display results in a tabular format)

 
Tim Moores
Saloon Keeper
Posts: 3889
91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In PromotionDB, does the loop add any elements to the ArrayList? Add some logging to find out for sure.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be putting any Java code into the JSP. Move the DB fetch code into normal classes which you can test to be sure the data is being fetch correctly.

Then in a servlet, call the classes to fetch the data and send it to the JSP for display.

Please see this article for a discussion of why Java web apps should be constructed that way.
 
Mohammed Sardar.
Ranch Hand
Posts: 187
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debugging or logging saves ton of time as this situation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!