DispatchAction应用

使用DispatchAction的代码:
package hb;

import java.util.List;

import org.apache.struts.action.Action;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;


import javax.servlet.ServletContext;
import javax.sql.DataSource;
import javax.servlet.http.*;


public final class LoginAction extends DispatchAction {
    
    public ActionForward login(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception {
              
        UserForm userform = (UserForm) form;        
String name = userform.getName();

if(UserDAO.chkUserName(name)>0){

   return (mapping.findForward("successed"));//登陆成功
  }
        else{return mapping.findForward(
"failed");}  

    }
    
    public ActionForward addUser(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception {
              
        UserForm userform = (UserForm) form;        
String name = userform.getName();

UserDAO userDao=new UserDAO();
         userDao.saveName(name);

   return (mapping.findForward(
"successed"));   

    }
    
    public ActionForward getUser(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception {
    
        HttpSession session = request.getSession(true);      
        UserForm userform = (UserForm) form;        
String name = userform.getName();
List list=null;

UserDAO userDao=new UserDAO();

list=userDao.getGbooks();
    session.setAttribute(
"userList",list);

   return (mapping.findForward(
"successed"));   

    }

}
LoginActionstruts-config.xml中的部署:
<action-mappings>
<action path=
"/login" type="hb.LoginAction" name="formBean1" scope="request" validate="false"  input="/error.jsp" parameter="method"/>
        <action path=
"/regist" forward="/addUser.jsp"/>
login.jsp相关代码:
<form action=login.do?method=addUser method=
"post">
<bean:message key=
"item.username"/>
<input size=
"15" name="name">addUser<p>
<html:submit>
<bean:message key=
"item.submit"/>
</html:submit>
</form>
<a href =
"login.do?method=getUser">getUser</a>



lunzi   2006-05-27 00:03:42 评论:1   阅读:1878   引用:0
@2007-01-13 14:19:30  游客
<action    path      = "/IntroductionView"
               type      = "EPC.Introduction.IntroductionModifyAction"
               name      = "IntroductionModifyForm"
               scope     = "request"
               validate  = "false"
               parameter = "method"
     >
        <forward name="IntroductionView

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog