• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

what if the 'starting' page needs some "action" ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally, we have JSP1 --> Actionservlet --> Action --> JSP2 scenario. But sometimes I want the "fisrt" JSP page NOT to be so simple, it should include some information that "action" class obtained from database at run time and display to user dynamically. In other words, I can't write a plain "JSP1". This beginning JSP page already requires some "action" and its content is a combination of static content and dynamic content obtained from the 'action'. So, how do I define such scenario in the "action mapping" section ?
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
personally, i don't think the flow is 'normal' in term of struts. it's highly recommended that you mask your jsp's with action mappings. keep in mind that an action mapping can be mapped to a jsp, tile, or another action. the main reason reason (again, personal take) is that if you have common tasks to be done via the controller, the entire app can be affected without 2 methods (1 for all the action and 1 for all the jsps).

this is a long-winded way to really say that instead of jsp1, you would define another mapping...say jsp1.do which is mapped to an action (where db values can be set) the forward the 'success' ActionForward to jsp1.jsp.
 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's see couple of examples --- I want to give user a "JSP1" page including a product list. This list should only include products that are currently available in the store database. So, I need to search database and dynamically find out the list and present it. Thus, this "JSP1" presentation already includes some "action" (search the avail. products). Of course, I can code the search part in JSP1 but it is ugly. I want to use struts and put it in Action. Now, the question is how to define the action mapping here ??
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you'd define it the same way you would define any action mapping.

in your action's execute(), call the database access method, grab the products, put the Product[] into a bean (say Products) then:

in your jsp then do a

then use logic:iterate or c:forEach to show your products.

if you don't know how to set up your application's "home" to point to this "product.do" as the default, you need to find out how or i can drop you a few hints. anything more would be writing codes line by line for you. slacker!
 
Shiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic