1.在Myeclipse建立一个Web Project,在最新的struts2 2.1.8.1中 需要加入的struts2包有6个(struts2-core,freemarker,ognl,xwork,common-logging,common-fileupload),如果是之前的版本则不用加入common-fileupload。
2.最新的2.1.8.1在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
3.在src中建立struts.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="struts2" extends="struts-default">
<action name="haha" class="com.test.action.haha">
<result>/index.jsp</result>
</action>
</package>
</struts>
4.然后在tomcat中的F:\java\apache-tomcat-6.0.24\conf\server.xml的</HOST>前加入
<Context path="/struts2" docBase="F:\java\works\struts2\WebRoot" reloadable="true" />
reloadable的意思是当项目改变时,tomcat会自己重启,然后就完成了项目在tomcat中的部署了!
5.在Myeclipse中启用tomcat:打开Myeclipse,Window-MyEclipse-Servers-Tomcat-Tomcat6.x,
单选Enable,在Tomcat home directory:中选tomcat的目录,如:F:\java\apache-tomcat-6.0.24
最后一个web基本可以跑起来了.