一增加struts2功能
1库ognl-2.6.11
struts2-core-2.0.6
xwork-2.0.1
2web.xml配置struts2的核心filter
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3struts.xml
<struts>
<package name="lee" extends="struts-default">
<action name="Login" class="lee.LoginAction">
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
二走向
1.login.jsp
<form action="Login.action" method="post">
2.filterDispatcher拦截转发请求(web.xml拦截;struts.xml配置中找对应action)
3action(struts2不再像struts1需要继承一个Action父类;它只是一个包含execute方法的普通Java类)
public class LoginAction implements Action {
public String execute() throws Exception {
if (getUsername().equals("pp") && getPassword().equals("911")) {
ActionContext.getContext().getSession().put("user", getUsername());
return "success";
} else {
return "error";
}
}
}
4导航转到对应的页面(根据struts.xml中的配置)