Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using bean:define

 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys. In a jsp page, I would like to escape html tags in a String object and found out that using struts bean will automate it. My problem is, how can I define an object from a session in jsp page and call its properties using <bean:write>

I can define its properties one by one like this:



And then

to print it out, but is there other way to Automate it? Without defining the properties one by one.

Thank you in advance
 
Ranjit Gopinathan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this .
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the "formName" is it the attribute name of the session object? Similar to



Thank you in advance!
 
Ranjit Gopinathan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
formName is the name defined in struts-config for the ActionForm associated with the Action.
eg:
<form-bean name="loginActionForm"type="com.form.LoginActionForm" />
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranjit.

There's no associated form in struts-config since the action is just to display the page. All objects are stored in session.

Thanks!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jazzy Sanchez:
All objects are stored in session.

In that case, there's no need for a bean:define tag at all. Just reference the profile bean directly. Example:

The scope="session" is optional, as Struts will search for a bean named profile in all scopes if it isn't specified.
[ August 06, 2007: Message edited by: Merrill Higginson ]
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked! Thanks Merrill
 
Kishore Sahu
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to use <bean:define> with <jsp:useBean> ???
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DontWakeTheZombies
Rather create a separate thread.

And <bean:define>, <jsp:useBean> worked as same with little difference.
Why do you want to mix up this tags, either use <bean:define> OR <jsp:useBean> .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic