views:

285

answers:

2

Hi,

How would I assign a variable within scriplet code in JSP <%> and then use struts logic tags to do stuff based on the value of the variable assigned in the scriplet code block?

I have tried using struts:logic equal and greaterthan to no avail....

Many Thanks,

+1  A: 

What you are trying to do (if I understand you correct) is basically this:

<% String foo = "Test"; %>
<bean:write name="foo" />

Which, as you already know, doesn't work. That would give an error like this:

Cannot find bean foo in any scope

What I usually do, is to put my data in the page scope like this:

<% pageContext.setAttribute("foo", "Test"); %>
<bean:write name="foo" />

(This is for Struts 1.1. Newer versions may provide a better way to do it.)

myplacedk
A: 

that makes some sense thanks, i will try it out

do you know why i cant do this

<% String foo = "Test"; %>

<%logic:equal name "foo" value= "test" %>

<bean:define id="JOININGDATE" name="smlMoverDetailForm"
property="empFDJoiningDate" type="java.lang.String" toScope="session"/>

<%/Logic:equal%>

(the bean:define part gets a value from the associated form bean and works while not in the logic tags)

You can't do that because the Struts Tags are translated into JSP. Here you are attempting to mix Struts *inside* JPS tags. This implies that Struts and JSP can be used with JavaScript and JSP can be used within Struts.
Randy Stegbauer