Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Bean Property in JSP  RSS feed

 
Michael Powe
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a JSP with the following tags:



The setter doesn't work -- I just get



when I retrieve the property:



However, if I insert this scriptlet immediately after the "useBean" tag, the property is set and I can retrieve it using the above getProperty tag:



So, without scriptlet, output is:



With scriptlet, output is:



I really want to know what I am doing wrong and would appreciate any tips. One thing it has occurred to me to note is that this page is actually being called through RequestDispatcher.forward() in a servlet. I don't know if that matters or not.

I'm writing this in NetBeans 5.5, using the bundled Tomcat, 5.5.17.

Thanks.

mp
[ May 19, 2007: Message edited by: Michael Powe ]
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The param attribute of the jsp:setProperty action refers to the name of the request parameter...But you have a request attribute named user
String str = (String) request.getAttribute("user");


So if you want the jsp:setProperty to work,use something like this

or
In case EL is not enabled try this:


Regards,
Srikkanth.M
 
Michael Powe
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The param attribute of the jsp:setProperty action refers to the name of the request parameter...But you have a request attribute named user


Bingo. I knew I had to be doing something simple yet wrong. Thank you very much. You know, I posted this question over at Sun Forums twice, lots of looks and no answers. I've obviously been spending too much time with the wrong crowd!

It does not appear that I have any way of passing in attributes without resorting to scripting. That is annoying. I'll have to rethink my approach.

Thanks again.

mp
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Powe:
It does not appear that I have any way of passing in attributes without resorting to scripting.
How so? Srikkanth Mohanasundaram showed you a way to do it with the EL rather than scripting.
[ May 19, 2007: Message edited by: Bear Bibeault ]
 
Michael Powe
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
How so? Srikkanth Mohanasundaram showed you a way to do it with the EL rather than scripting.


Sorry, probably careless usage on my part. I am thinking in terms of a purely tag-based approach and to me EL looks like script. Even though, it is not classed equivalently with scriptlets.

Thanks.

mp
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modern JSP pages heavily employ the JSTL and EL to accomplish their task. Take the EL out of the mix and you've got very little left to work with.

The property manipulation tags and scriptlets are now considered passe and you should be focusing on JSTL and EL.
[ May 20, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!