运用类反射机制简化Struts应用程序开发

http://tech.ddvip.com   2007年07月04日    社区交流

内容摘要:运用类反射机制简化Struts应用程序开发

  3、 在JavaBean封装的商业逻辑中调用Select 方法,然后在JSP页面上显示出来:

//Function:取得用户列表
 //Para:
 //Return:返回用户列表
 public ArrayList getUsers(){
   ArrayList ret=null;
   DatabaseManage db=new DatabaseManage();
   String sql=" select usr_id,usr_name "
     +" from users " ;
   ret=db.Select(sql," com.bhsky. webis.system.UsersActionForm");
   return ret;
 }

  4、 在Action的execute方法中调用getUsers()方法:

public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse httpServletResponse)
  {
  /**@todo: complete the business logic here, this is just a skeleton.*/
  UsersActionForm uaf=(UsersActionForm)actionForm;
  SystemService ubb=new SystemService();
  ArrayList userList=ubb.getUsers();
  request.setAttribute("userList",userList);
  ActionForward actionForward=actionMapping.findForward(url);
  return actionForward;
 }

  5、 在JSP中显示:

<table width="700" class="1" border="1" cellspacing="1" align="center">
    <tr>
     <td class="list" >用户ID</td>
     <td class="list" >姓&#160&#160名</td>
    </tr>
    <logic:present name="userList" scope="request">
     <logic:iterate name="userList" id="userList"
type="com.bhsky.webis.system.UsersActionForm">
    <tr>
     <td class="cell1" height="22"><bean:write name="userList"
property="usr_id"/></td>
     <td class="cell1" height="22"><bean:write name="userList"
property="usr_name"/></td>
    </tr>
    </logic:iterate>
   </logic:present>
</table>

责编:豆豆技术应用

正在加载评论...