Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to assign ${somevalue} to a bean using jsp:setproperty

 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to set a value to the bean.
The value is from DB

<sql:query var="items">
SELECT name FROM emp
</sql:query>

<c:forEach var="row" items="${items.rows}">
<jsp:useBean id="empName" class="test.emp">
<jsp:setProperty name="empName" property="empName" value="${row.name}"/> </jsp:useBean>

The value that is setting is
${row.name}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64610
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a bean named empName and a property named empName. Bad idea. Very confusing and likely to lead to name collisions.

Either use the JSTL or don't. There's no need to use <jsp:setProperty> if <c:set> is available.
 
Ravi Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,
I used the following code
<jsp:useBean id="chkBxNm" scope="session" class="TUnit.TUnitNmBean" />
<c:set target="${chkBxNm}" property="TSName" value="${row.TSName}" />
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic