Struts logic标签及增删改查

21 篇文章 0 订阅
9 篇文章 0 订阅

-------------------------------------------------老师写的 Acion--------------------------------

 

public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  String type = request.getParameter("type");
  ActionForward actionForward = null;
  if ("insert".equals(type)) {
   actionForward = insert(mapping, form, request, response);
  } else if ("delete".equals(type)) {
   actionForward = delete(mapping, form, request, response);
  }else if ("queryAll".equals(type)) {
   actionForward = queryAll(mapping, form, request, response);
  }
  
  return actionForward;

 }

 

-------------------------------


 public ActionForward insert(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {

  // 获取表单中的值 插入到数据库中
  UserForm userForm = (UserForm) form;
  UserModel userModel = new UserModel();
  userModel.insertUser(userForm);
  return mapping.findForward("query");
 }

 public ActionForward delete(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {

  UserModel userModel = new UserModel();
  int id = Integer.parseInt(request.getParameter("id"));
  userModel.deleteUser(id);
  return mapping.findForward("query");
 }
 public ActionForward queryAll(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {

  UserModel userModel = new UserModel();
  List list=userModel.queryAll();
  request.setAttribute("LIST",list);
  
  return mapping.findForward("list");
 }

 

 

-------------------------------------------------------------------------------------

Action里写的


  UserModel userModel = new UserModel();
  List list=userModel.queryAll();
  request.setAttribute("LIST",list);

-------------------------------------------Select.jsp-----------------------------------------------------------------

<logic:iterator id="U" name="list">  name就是request.getAtribute的名字

直接使用就不用

<bean:write name="U" property="id">

<bean:write name="U" property="username">

<bean:write name="U" property="password">

</logic:iterator>

--------------------

<beanLwrite  name="" property="">

name 就是 要打印的对象或是得到的setAtribute("s",s)中的"s" 而property是对象中的属性

-------------------------------------------------------------------------------------

Ps:今天老师讲的有点乱..

 查询的时候需要新增加个 Aciton

<action path="/userQueryAll" type="net.dbet.struts.action.UserAction">

而 删除的时候又 增加个 Action

<action path="/userDelete" type="net.dbet.struts.action.UserAction">

但是  我问 老师说 可以 把 删除的 和 查询的放到一起....  如果有验证 就会报错..

 真是愁人  不知道有没有什么办法 可以 把 validate  固定再 想用的地方 .... 无语

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值