wood burning stoves 2.0*
The moose likes JSP and the fly likes Using JSTL / EL to grab parameter names and values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using JSTL / EL to grab parameter names and values" Watch "Using JSTL / EL to grab parameter names and values" New topic
Author

Using JSTL / EL to grab parameter names and values

Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Dec 16, 2007
Posts: 41
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


sakthi SCJP, SCWCD OCA
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Dec 16, 2007
Posts: 41
sorry for inconvenience

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

sorry if i am wrong.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

...

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

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

And param[pname] doesn't work?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
David Newton wrote:And param[pname] doesn't work?


ah, yes that does. Thankyou
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

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}


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using JSTL / EL to grab parameter names and values
 
Similar Threads
how to set space between item cells in spring mvc form controller
Extracting a parameter from c:out value
JSP column name hyperlink help
JSF TreeMap Iteration Problem Using JSTL In XHTML
How to pass JSTL value to javascript function