Struct2
------------------------------------------------------------web.xml ------------------------------------------------------------------
web.xml 中的配置
<!-- 拦截器配置 开始 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 拦截器配置 结束 -->
--------------------------------------------------------------------Structs.xml ---------------------------------------------------------
Structs.xml
Structs.xml 放在src 根目录下
以下是子文件 也放在src 根目录下
struts-use.xml
struts-note.xml
struts-friend.xml
struts-art.xml
Structs.xml
中的详细配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-use.xml" />
<include file="struts-note.xml" />
<include file="struts-friend.xml" />
<include file="struts-art.xml" />
</struts>
-----------------------------------------------struts-use.xml文件 详细配置 案例----------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="use" extends="struts-default">
<!-- 登陆的 ACTION -->
<action name="mylogin"
class="com.isoftstone.xiaonei.use.web.action.LoignAction"
method="checkLogin" >
<result name="success">/result.jsp</result>
<result name="fail">/use/login.jsp</result>
</action>
<action name="reg"
class="com.isoftstone.xiaonei.use.web.action.LoignAction"
method="saveUser" >
<result name="reg">/use/reg.jsp</result>
<result name="fail">/use/login.jsp</result>
</action>
</package>
</struts>
-------------------------------------com.isoftstone.xiaonei.use.web.action.LoignAction-----------------------------------
package com.isoftstone.xiaonei.use.web.action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.isoftstone.xiaonei.pojo.Users;
import com.isoftstone.xiaonei.use.service.IUserService;
import com.isoftstone.xiaonei.use.service.impl.UserService;
import org.apache.commons.logging.*;
/**
*
* @author ���յ�
* @����ʱ�䣺Jun 29, 2010 2:37:59 PM
* @��Ŀ��xiaonei
* @�ļ���LoignAction.java
* @����com.isoftstone.xiaonei.use.web.action
*/
public class LoignAction implements ServletRequestAware {
Log log=LogFactory.getLog("loginlog");
private Users user=new Users();
HttpServletRequest request;
private String errorMsg;
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
/**
*
* @������execute
* @����
* @return
* @throws Exception
* @�½����ڣ�Jun 29, 2010 2:41:42 PM
public String execute()throws Exception{
System.out.println("-----------"+user.getLoginName()+"----------------");
return "success";
}
*/
/**
*
* @������checkLogin
* @����
* @return
* @throws Exception
* @�½����ڣ�Jun 29, 2010 5:11:11 PM
*/
public String checkLogin(){
log.fatal("This is a fatal message.");
log.error("This is a fatal message.");
log.debug("This is a fatal message.");
IUserService iUserSer=new UserService();
if(iUserSer.checkLogin(user.getLoginName(), user.getLoginPwd())){
return "success";
}
request.setAttribute("errorMsg", "对不资1�7,您输入的用户名或密码不正硄1�7!");
return "fail";
}
public void setServletRequest(HttpServletRequest arg0) {
this.request=arg0;
}
public String saveUser(){
IUserService iUserSer=new UserService();
if(iUserSer.saveUser(user)){
request.setAttribute("regSuccess", "��ϲ�㣬ע��ɹ���");
return "fail";
}
request.setAttribute("regFail", "ע��ʧ�ܣ�");
return "reg";
}
}