This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Assigning a java variable a value from struts tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Assigning a java variable a value from struts tag" Watch "Assigning a java variable a value from struts tag" New topic
Author

Assigning a java variable a value from struts tag

Gary Jones
Greenhorn

Joined: Dec 11, 2004
Posts: 22
Can we mix java code and struts together.
Meaning if I want to assign a java variable a value which is stored in a struts tag or form bean property
<%
String str = <bean:write name="myBean" property="midrange"/>;
System.out.println("string ::"+str);
%>

This obviously fails..giving a compile time error.
How do i assign values stored in beans to java variables.
Excuse me for writing scriplets in jsp page when we really have struts framework.Its a temp solution.


<blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>I have no special talent. <b>I am only passionately curious.</b> <br /> <br />Albert Einstein <hr></blockquote>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can't insert a <bean:write> tag inside a java scriptlet. However, everything that a <bean:write> tag can do, you can do in java. You just have to change the syntax.

So, in your example:

String str = ((MyBean)request.getAttribute("myBean")).getMidrange();


This is assuming that myBean is in request scope.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assigning a java variable a value from struts tag