How can I expose a Java bean to a JSP page by using struts? I know how to configure a StrutsAction to include a form-bean, but I wonder if there are other ways to interact with Java code from a JSP page? I ask this question because I don’t understand fully a likely answer to a problem that I have asked here:
Clean way for conditionally rendering HTML in view?
EDIT:
I understand that a JavaBean is defined as a class that contains mainly getters and setters for its properties.
My problem was that I did not see how I can access parameters from Java classes in my JSP. Currently, I use a DynaForm to communicate parameters to the view. E.g. in the ActionClass I set the parameter, and in the JSP I can access it with
bean:write name=”MyFormBean” property=”myParameter”
My question was basically if there are other classes than a DynaForm class that can easily be accessed from inside the JSP with tags, and if so, if someone could provide an example.
In your action class:
In your JSP:
You can do the same with session as well. Note that you don’t have to explicitly specify the scope in
<bean:write>tag – if you don’t, Struts will look in all scopes from page to application.More information on scopes is available in Java EE tutorial.