public interface ActionManager {
/**
* ¸ù¾ÝÓû§Ãû£¬ÃÜÂëÑéÖ¤µÇ¼ÊÇ·ñ³É¹¦ * @param username µÇ¼ËùÊäÈëµÄÓû§Ãû * @param password µÇ¼µÄÃÜÂë */
Integer validLogin(String username , String password); }
2. ÔÚcom.service.impl°üÖд´½¨ÒµÎñÂß¼²ã½Ó¿ÚµÄʵÏÖÀ࣬Èçͼ7.
ͼ7 ActionManagerʵÏÖ½Ó¿Ú
package com.service.impl;
import com.dao.UserDAO;
import com.domain.Users;
import com.service.ActionManager;
public class ActionManagerImpl implements ActionManager{
public Integer validLogin(String username, String password){
try
Users user = userDAO.findUserByNameAndPass(username, if (user!= null) { }
return user.getId();
{
private UserDAO userDAO;
public void setUserDAO(UserDAO userDAO) { }
this.userDAO = userDAO;
password);
}
catch (Exception e)
}
{
System.out.println(e.getMessage()); } }
return null;
ËÄ¡¢
¿ØÖƲãÉè¼ÆÓëʵÏÖ
1. ActionµÄ´´½¨
£¨1£©ÔÚcom. action°üÖд´½¨Action¡£Èçͼ8.
ͼ8 µÇ¼Action
// LoginActionÔ´ÂëÈçÏ£º
package com.action;
import com.service.ActionManager;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
public String execute() throws Exception {
}
Integer userId = mgr.validLogin(username, password);
if (userId != null) { }
return SUCCESS;
addActionError(\Óû§Ãû/ÃÜÂ벻ƥÅä\); return \; } else {
return \;
protected ActionManager mgr;
private String username; private String password;
private static final long serialVersionUID = 1L;
if(username.equals(\) || username == null){
}
public String getPassword() { }
public String getUsername() { }
public void setPassword(String password) { }
public void setUsername(String username) { }
this.username = username; this.password = password; return username; return password;
public void setMgr(ActionManager mgr) {
this.mgr = mgr;
}
public ActionManager getMgr() {
return mgr;
} }
2. Struts2¿ØÖÆÎļþºÍÊôÐÔÎļþµÄÅäÖà (1) actionµÄÅäÖÃ
ϵͳÉú³ÉµÄStruts.xmlÄ£°åΪ£º
//struts.xml
ÅäÖÃ×ÊÔ´×ÔºóµÄStruts.xmlΪ
//struts.xml
value=\ /> struts.properties // struts.propertise struts.locale=zh_CN struts.i18n.encoding=UTF-8 struts.objectFactory = spring struts.objectFactory.spring.autoWire = name struts.multipart.parser=jakarta struts.action.extension=action struts.serve.static=true struts.serve.static.browserCache=true struts.enable.DynamicMethodInvocation = true struts.enable.SlashesInActionNames = false struts.tag.altSyntax=true struts.devMode = false struts.i18n.reload=false struts.ui.theme=xhtml struts.ui.templateDir=template #sets the default template type. Either ftl, vm, or jsp struts.ui.templateSuffix=ftl struts.configuration.xml.reload=false ### Location of velocity.properties file. defaults to velocity.properties struts.velocity.configfile = velocity.properties ### Comma separated list of VelocityContext classnames to chain to the StrutsVelocityContext struts.velocity.contexts = ### Location of the velocity toolbox struts.velocity.toolboxlocation= ### used to build URLs, such as the UrlTag struts.url.http.port = 80 struts.url.https.port = 443 ### possible values are: none, get or all
Ïà¹ØÍÆ¼ö£º