• 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

Using JSTL / EL to grab parameter names and values

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I need a way of grabbing the request parameter names and values to print to the page (jsp)

So far I am able to grab the names and print them, Im unsure of how I would get the values.

my code:


Thanks
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi mark
The parameter values are stores in request object so you can get the value using getAttribute(paramName, scope) method in PageContext class.

remember getAttribute returns Object type.

<c:out value="pageContext.request.getAttribute("${pname}", PageContext.REQUEST_SCOPE)" />

try this
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sakthi vadivel wrote:hi mark
The parameter values are stores in request object so you can get the value using getAttribute(paramName, scope) method in PageContext class.

remember getAttribute returns Object type.

<c:out value="pageContext.request.getAttribute("${pname}", PageContext.REQUEST_SCOPE)" />

try this



Thanks, but this does not work. It may be something to do with the quotes, they need to be escaped or something. Im new to EL and JSTL, but I know using a scriplet I could say
 
sakthi vadivel
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for inconvenience

you can try using pageScope object in EL. ${pageScope["requestparamName"]}.

sorry if i am wrong.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sakthi vadivel wrote:sorry for inconvenience

you can try using pageScope object in EL. ${pageScope["requestparamName"]}.

sorry if i am wrong.



Thanks for the help, but this gets the parameter names. Im after the values.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Five seconds on Google (almost assuredly quicker than waiting for something to answer your question):

http://www.oracle.com/technology/products/jdev/collateral/papers/10g/jstl_el_adf/jstl_el_adf.html
http://www.exampledepot.com/egs/javax.servlet.jsp.jstl.core/getparam.html
http://www.informit.com/articles/article.aspx?p=30946
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried googling. Im after a print out of the parameter names and values. I cant grab the values without knowing the names, and im unsure of how to use EL to loop around all the names and use each one to find the value. I can do it quite simply using scriplets but they are messy.

${param.name} would only get the value of the parameter called "name"
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...

Loop over the names and use each name in the EL to get the parameter.

Why would you want to do this, anyway?
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was my plan. But im unsure how to get the value - see my code in first post.

Its for an error (HTTP 500) page for a big app that has lots of bugs. Reporting the parameters will be useful in saving time debugging
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And param[pname] doesn't work?
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:And param[pname] doesn't work?



ah, yes that does. Thankyou
 
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

sakthi vadivel wrote:
<c:out value="pageContext.request.getAttribute("${pname}", PageContext.REQUEST_SCOPE)" />

try this


This is nonsense. You can't call methods using the EL.

If you want to get at individual parameters, just use the param builtin map: ${param.name}
reply
    Bookmark Topic Watch Topic
  • New Topic