Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Assigning a java variable a value from struts tag

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I like tacos! And this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic