I want to access from bean object in jsp page. How to get that?
I have formbean class with customername,date,amount,rate etc with setter() and getter() for the field members.
I have data access class where i can get data for the bean class property from database and set data to formbean class object
E.g.:
class formbean{
String amount;
String rate;
public void setAmount(String amount) {
this.amount=amount
};
String getAmount() {
return amount;
}
...
}
class dao {
public Formbean fetchcust() {
loan.setCloseDt11(rs.getString("CloseDt"));
loan.setAmount11(rs.getString("Amount"));
loan.setRate11(rs.getString("Rate")); return loan;
}
}
and returning this object.
my question is how to access this object in jsp page
If your bean is an ActionForm (it’s not clear from your code if it is or not) then Struts exposes this into you JSP files and you have access to it from tags within <html:form>
. You then just use the property
attribute on the Struts tags and they will pick that up.
Also, you can have access to it by using JSTL or Struts bean tags since Struts exposes this in the request or session scope as a named attribute (the scope is specified in the struts-config.xml
file in your action
definition using the scope
attribute and the exposed name is the name
attribute of the same definition).
<action
path="/actionName"
type="some.package.ActionClass"
name="yourForm"
scope="request"
...
>
If that form is a standard bean, not extending ActionForm than you must set this in the desired scope by hand using request.setAttribute(…)
or session.setAttribute(…)
. Once in the JSP you can retrieve it using again JSTL or Struts bean tags.