File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JSTL / EL to grab parameter names and values

 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
sakthi vadivel
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And param[pname] doesn't work?
 
Mark Wa
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:And param[pname] doesn't work?


ah, yes that does. Thankyou
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic