struts2--login例子
刚接触struts2,学习中...先做个登陆的例子
1、建立web项目
2、导入struts2的jar包
??? commons-fileupload-1.2.1.jar?
??? commons-io-1.3.2.jar?
??? commons-logging-1.0.4.jar
??? freemarker-2.3.15.jar?
??? ognl-2.7.3.jar?
??? struts2-core-2.1.8.1.jar?
??? xwork-core-2.1.6.jar
官方下载地址:http://struts.apache.org/download.cgi#struts2014
3、配置WEB-INF/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>
<!-- filter-class中也可以写成org.apache.struts2.dispatcher.FilterDispatcher -->
注:StrutsPrepareAndExecuteFilter是struts2 2.1.*之后的才有的,2.0.*没有该filter,之前为FilterDispatcher.
该系统使用struts2-core-2.1.8版本
4、配置src/struts.xml,最后看看WEB-INF/classes下是否存在
<?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="struts" extends="struts-default">
????? <action name="login" extends="struts-default" namespace="/">