how to access formbean class obj in jsp page

丶灬走出姿态 提交于 2019-12-24 20:25:57

问题


I want to access from bean object in jsp page. How to get that?

  1. I have formbean class with customername,date,amount,rate etc with setter() and getter() for the field members.

  2. 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


回答1:


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.



来源:https://stackoverflow.com/questions/2264388/how-to-access-formbean-class-obj-in-jsp-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!