• 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

Getting a value from a URL

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have a struts app which is going to be brought up via a hyperlink on a non-struts application. The hyperlink will be passing my application a userID on the URL. I am having a hard time figuring out where/how to access it.

The URL looks like this:
http://localhost/bedRequest/main.do?&UserID=2

I want to get the UserID value when my application session starts up. I thought I could get it from the class I have which extends the struts RequestProcessor class, but when I debug, the value is not in the HttpServletRequest.

Is the syntax of the hyperlink wrong? Should I be accesssing the value on the URL someplace else?

Thanks in advance!
Kim
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could have the link execute a dispatch action which accepts a value as an argument and pass the user as the argument via the line.

Or sticking with your current method you could use:



where request = HttpServletRequest
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply. I did a call to that method, but the value I returned was http://localhost/bedRequest/main.do

I had typed http://localhost/bedRequest?&UserID=2 into the browser.

I then tried a differant version: http://localhost/bedRequest/main.do
?UserID=2 into the browser, and the call to getURL still returned
http://localhost/bedRequest/main.do.

Maybe I need to add something to the struts config file where I define my request Proccessor ?

 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hrm, maybe try a dispatch action. I've passed IDs through the URL before using that method. If I get a few minutes here I'll look for some sample code.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kim Kantola:
when I debug, the value is not in the HttpServletRequest.


I seriously doubt that this is the case. The value is in the HttpServletRequest in the form of a parameter, not an attribute.

All you have to do get the value is this:

Whether you retrieve this value in your RequestProcessor or in an Action class, the value should be available.

Regarding Chris' suggestion to use a DispatchAction, that sounds like overkill to me. Just get the value as I have shown above and use it however you need to.
 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good call, overlooked the most simple of all.
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doh! You are right, The value was there and I saw it with the
String userId = request.getParameter("UserID");

I was looking and looking for it with my debug messages, I think this is like one of those cases where something will not work, but when you ask someone to help you and you try to show them it not working, it decides to work! The whole "someone looking over your shoulder" effect!

Thank you both so much for your input,
Kim
 
Yeah, but does being a ninja come with a dental plan? And what about 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