Setting Bean Properties in JSP

Second try on this question.

I have a JSP with the following tags:

<jsp:useBean class="org.trollope.DbAccess" id="dba2">

<jsp:setProperty name="dba2" param="user" property="jdbcUser"> </jsp:setProperty>

</jsp:useBean>

It doesn't work -- I just getnull

when I retrieve the property:

Bean property is: <jsp:getProperty name="dba2" property="jdbcUser"></jsp:getProperty>

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:

<%

String str = (String) request.getAttribute("user");

dba2.setJdbcUser(str);

%>

So, without scriptlet, output is:

Bean property is:null

With scriptlet, output is:

Bean property is: powem

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.

Thanks.

mp

[1398 byte] By [naugiedoggiea] at [2007-11-27 4:50:51]
# 1

Solved via Java Ranch.

The answer is:

<setProperty name="dba2 param="user" property="jdbcUser" />

param refers to a request parameter but I was using it to refer to a request attribute. This works:

<setProperty name="dba2" property="jdbcUser" value="<%=request.getAttribute(\"user\")" %>

That is still ugly because I'm trying to avoid scripting, but now I know what was the problem and I can work out a solution.

Thanks.

mp

naugiedoggiea at 2007-7-12 10:04:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...