• 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

read value from URL and process on page (keep mvc pattern)

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

Here is the deal: I have a registration page which the user has to fill out - http://localhost/registration.jsp . The user may �arrive� from a different URL to this page (example user clicks the link: http://localhost/registration.jsp?id=996

The id is the value I would like to retrieve in order to show different values on the registration.jsp page. For example, with id 996 � show a truck and title, with 443 � show an SUV and info.

Question: how can I construct the page based on the id values? The problem I�ve encounter is that the page is processed (Action) only after the user has clicked submit.

With the given id (before reaching the registration.jsp) , I will have to go to the db fetch some info and plug it back to the registration page. I don�t wish to do that (action) in the jsp because I wish to keep the MVC pattern.

One thought I had in mind is to use an intermediate page / intermediate.jsp?id=996
that will be redirected to the registration.jsp with the id value and beans (but I wonder if there�s a better way to do that)

thanks for any thought
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe mapping can be tweaked to have registration page request processed through action servlet, If that doesn't work then you have to use http-equiv meta redirect in the registration jsp page to make the request to an action.
See http://www.html-reference.com/META_httpequiv_refresh.htm on how to redirect from client side.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of forwarding directly to the jsp, I would use a "display" action instead. Forward to that action and have the code there do the processing you need. Your url would then look something like http://localhost/displayRegistration.do?id=996

- Brent
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,
If I understand you correctly, you're saying I should have a �previous page�: displayRegister that takes the id and fw it to the registration.jsp.

Basically, in between I can have displayRegisterAction - get the ID and make any init, setup I want. Right?

1. Is this the process you had in mind?
2. if displayRegister is just a redirect do I still need to create for it a bean? or in other words, what's the shortest way to get to the displayRegisterAction, read the id and fw to registration.jsp
3. what code will be in the displayRegister.jsp to ignite displayRegisterAction?

Thanks
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#1 - Yea, I think that is what I had in mind.

#2 - Just a redirect? I was under the impression that you would need code to read a record from the database to populate the jsp page. I am picturing that your action would look like this:


#3 - I am not sure what you are asking here. The file displayRegister.jsp will probably submit to an action that saves the registration data (maybe saveRegistration.do).

- Brent
[ October 17, 2006: Message edited by: Brent Sterling ]
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

I did that and it works!

So it works like this: user clicks a url with displayRegistration?id=344
and that is redirected to registration.jsp with the id.
in-between I do some business logic in the displayRegistrationAction.

the only thing, which i suspect to be a bit incorrect, is my struts-config action-mapping:

I did this;

path=displayRegistration
type=com.action.displayRegistrationAction
name=myForm //??? this belongs to something else
scope=request
input=/displayRegistration
validate=false
.
.
.

the displayRegistration.jsp has NOTHING in it - so it goes directly to the displayRegistrationAction (great)-> business --> fw to the registration with attribute

my question is this: do you think the mapping-action for this action is ok? I mean I don't use any form, no need to validate and NO BEAN!
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not using a form bean, you can delete the form attribute from your action definition (just delete that entire line). The form parameter that gets passed into the execute method will be null.

- Brent
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Brent, you tought me something new today.
(oh...new icon)
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic