• 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

request scope question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, forgive me for asking a newb question at JSP- I started on it (and Struts) less than two days ago, and I have a project I need to get going, very badly.

If I have a jsp, and I want to have an action tied to a command button, and I want to maintain the current request (and a certain attribute of that request) while passing it on, I know I need to keep forwarding the request.

So, instead of saying in my jsp something like:
<html:form action="/emailContactInfo">
(where /emailContactInfo is one of my mapped actions in struts-config.xml)
I suspect I need to forward somehow to that same mapped action, to avoid losing the current request.

First, am I right? Second, can you point me at something that can very clearly explain how I would tie something like a <jsp:forward etc /> to a command button ( well an <html:submit etc />)?

I've no objection to reading- but I have to know it will pay off; I am rather short on time (one day left). Any help would be MUCH appreciated!
Actual examples of something similar would be great. I am hunting through all my newly purchased Struts books with no luck. I should have gotten JSP books too, but I didn't know at the time.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Neel Taylor:
If I have a jsp, and I want to have an action tied to a command button, and I want to maintain the current request ...


No can do. The "current" request goes out of scope as soon as the page is sent to the browser. There's no hope of hooking back up to it because it's long dead and gone before the user ever sees the button.

If you need to maintain a value across multiple requests you can either maintain it in a hidden parameter on the page (only suitable for text or simple values), or in the session.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Is there a reason that you are adopting Struts prior to understanding Servlets and JSP? Unless it's forced upon you, it's best to learn the underlying technologies before adopting a framework.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.P.S. If you are just starting out with JSP, I'd recommend taking at gander at these articles:

The Secret Life of JavaServer Pages
The Front Man
[ August 31, 2008: Message edited by: Bear Bibeault ]
 
Neel Taylor
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
P.S. Is there a reason that you are adopting Struts prior to understanding Servlets and JSP? Unless it's forced upon you, it's best to learn the underlying technologies before adopting a framework.



Very, very much forced upon me- it's a test to see how quickly I can learn things I haven't done before.
 
Neel Taylor
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:

No can do. The "current" request goes out of scope as soon as the page is sent to the browser. There's no hope of hooking back up to it because it's long dead and gone before the user ever sees the button.

If you need to maintain a value across multiple requests you can either maintain it in a hidden parameter on the page (only suitable for text or simple values), or in the session.



So if I need to have a data entry page, and a confirmation page that either does something with the information if it is accepted, or returns to the data entry page if it is not, would session-scoping be appropriate?
 
Neel Taylor
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Neel Taylor:


So if I need to have a data entry page, and a confirmation page that either does something with the information if it is accepted, or returns to the data entry page if it is not, would session-scoping be appropriate?



or could I rebuild the form-bean on the confirmation page and send the new one on? All the information is displayed there, so I have to think the data is there to work with.

Meanwhile, I am reading your suggested items. Thanks!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As this starts to get involved with Struts forms, I'm going to move this to the Struts forum where the Struts-savvy can advise you.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd recomend against session scoping your application data, it will prevent you from taking advantage of struts' ability to automatically populate the fields in your form class.

If your struts-config.xml file is going to forward the results to another action I would set the values you need in the next action as attributes in your request object so they can be picked up by the next action.
 
Don't mess with me you fool! I'm cooking with gas! Here, read 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