首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Struts logic标签及增删节查

2012-10-31 
Struts logic标签及增删改查-------------------------------------------------老师写的 Acion----------

Struts logic标签及增删改查

-------------------------------------------------老师写的 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? 固定再 想用的地方 .... 无语

热点排行