• 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

Converting request parameters to JSP tag-file attributes

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP that invokes a tag-file with some attributes as defined in the tag-file. I want to convert the request parameters that I receive for this JSP as attributes to the tag-file dynamically. For eg., If my JSP file is sample.jsp and it's contents are :

And I receive attr1,attr2 as request parameters in my JSP - say /sample.jsp?attr1=value1&attr2=value2..., How do I pass on the same as attributes to the tag-file?
I tried using JSTL tags in the JSP to generate run-time attributes like below, but no luck!

When I try the above code, I get

   "Expression language not allowed in a template text body."

I've declared the tag's body-content as "scriptless" with dynamic-attributes enabled. As rtexprvalue of a JSP attribute defaults to true, I don't understand why this exception occurs. Any help would be greatly appreciated!
 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you passing parameter to that jsp? try <jsp:param> tag, I am also confussed in your question talking about parameter or attribute.
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhumitha,

"Expression language not allowed in a template text body."


With the <jsp:attribute> you are defining attributes for the enclosing <c:forEach> tag, and if you do that you have to define a <jsp:body> (because the body of <c:forEach> is not defined as empty)...

I guess you want to add the parameter names and parameter values as attribute names and attribute values to the <tag:showTag>, don't you? Can you show us your tld entry or tag-file and your showTag implementation?

Have you thought of this construction?


Regards,
Frits
 
Madhumitha Subramanian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudhakar and Fritz,

  Thanks for the replies.

@Sudhakar
When I try the jsp:param, I get

  "The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements"

Quite expected, as I want them to be passed on as attributes to the showTag tag and not as parameters.

@Fritz

With the <jsp:attribute> you are defining attributes for the enclosing <c:forEach> tag, and if you do that you have to define a <jsp:body> (because the body of <c:forEach> is not defined as empty)



  Alrite, this din't strike me before. So what I want to achieve looks quite impossible now Anyways, I want to add parameter name as attribute name and the parameter's value as attribute's value to the tag-file.

So when I make a request like /sample.jsp?attr1=value1&attr2=value2&...

I want to convert this to : <tag:showTag attr1=value1 attr2=value2/> in the JSP file

And my showTag.tag file is something like this :



  Trust I was clear. Any possible solution to this?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Any possible solution to this?


Well I am still not sure what you are trying to do with this <tag:showTag>. What should the jsp do with the parameter names and parameter values? If you would have posted your implementation I could have suggested a solution. It seems you didn't like the one I posted earlier?

What about this one (making use of dynamic attributes in a tag-file)
The JSP-file:


and the tag-file

with a url of:

http://localhost:8080/TestWeb/showparamsTagfile.jsp?attr1=a&attr2=b


having a result of:


name attr2
value b
name attr1
value a


Regards,
Frits
 
Is that a spider in your hair? Here, threaten it with this 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