初试Struts2的一些收获
时间:2010-08-20 来源:Fly龙
要使用Struts2架构,首先要进行一些设置
1.在tomcat的根目录的webapps文件夹下找到项目是使用Struts2架构的文件的根目录(假设我测试Struts2时用的项目名是MyStruts2,即是\tomcat的根目录\webapps\MyStruts2) ,在该路径下设置一些相应的文件和文件夹。如下两幅图所示
2.然后设置 web.xml 的内容
<web-app 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"
version="2.5">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
3.设置classes文件夹下的struts.xml配置文件
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="strutsqs" extends="struts-default">
<action name="Login" class="cn.struts2.LoginAction">
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
<result name="input">/Login.jsp</result>
</action>
<action name="GetBooks" class="cn.struts2.GetBooksAction">
<result name="login">/Login.jsp</result>
<result name="success">/showBook3.jsp</result>
<result name="error">/Login.jsp</result>
</action>
</package>
</struts>
4.在lib文件夹引入struts2的jar包
这样就将struts2的基本架构建立起来了!可以启动tomcat来测试相关jsp网页!