日期:2014-05-19 浏览次数:20812 次
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>first Struts 2 Project</display-name>
<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>
</web-app>
<?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-default.xml"/>
<!--指定web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding的方法 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="do" />
<!-- 开发模式下使用,这样可以打印更详细的错误信息 -->
<constant name="struts.devMode" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<package name="express" extends="struts-default">
<!-- 用户登录校验 -->
<action name="checkLogin" class="express.action.LogIn" method="checkLogIn">
<result name="success">/successed.html</result>
<result name="login">/failed.html</result>
</action>
<!-- 默认ACTION -->
<action name="index">
<result>/index.jsp </result>
</action>
</package>
</struts>
package express.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import ctrl.Check_Id;
public class LogIn extends ActionSupport {
private String id;
private String pass;
private Check_Id ch=new Check_Id();
public void setId(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
public String checkLogIn() {
if (ch.checke(this.id, this.pass))// 发送密码和ID给业务处理层,并按结果操作
{// 成功就给session赋值,并跳转到成功页面
ActionContext ac = ActionContext.getContext();
ac.getSession().put("ID", this.id);
return SUCCESS;
} else {// 否则跳转到失败页面
return LOGIN;
}
}
}
信息: Starting Servlet Engine: A