• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populating Struts Form on JSP init() or onload()

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have an default page that needs to be populated with values from the database whenever the page loads up. I'm using Struts in my JSP pages.

Currently I have a Java class that retrieve values from the database.
However, I don't know how to assign these values on my Struts form properties when the page loads up for the first time.

Can someone show me an example of how to load form values on a default jsp page using Struts?

I would appreciate your help...
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to do this is to put the logic that loads the data into an Action class and have that action class forward to the JSP that displays it.

If you want to make it work in a welcome page, one way to do it is to have an index.jsp with only the following lines:

Where myAction is the action that loads the data and forward to the JSP.
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your suggestion. Yes, I would like to load default data on the Welcome page.

I tried <logic:redirect forward="myAction"/>.

The only problem is, my Welcome page is now stuck in an infinite loop. Each time the page loads up, it is sent right back to the redirect again. As a Result, the Welcome page never comes up.

Does anyone have any suggestions???
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this example myAction must forward to a different JSP than the one that redirected to myAction. This redirect statement should only go in your index.jsp and nowhere else.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic