eclipse中配置struts2
2011-08-12 14:18
246 查看
1.建立web工程
选择Dynamic Web Project,然后next
2.输入项目名称,选择Target Runtime,点击new选择apache Tomcat 5.5,finish
3.添加strut2开发包,把下面的6个jar包拷贝到webContent/WEB-INF/lib里
commons-fileuploader-1.2.1.jar//好多介绍里没有引进这个包,不过这个貌似也要引进来,否则会提示Unable to load configuration. - bean - jar错误
commons-logging-1.0.4.jar
freemarker-2.3.12.jar
ognl-2.6.11.jar
struts2-core-2.1.2.jar
xwork-2.1.1.jar
拷贝完成后refresh,新加的jar包会显示到下图的位置
3.修改webContent/WEB-INF/web.xml,修改后的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
tutorial</display-name>//这里是你建立的工程的名字
<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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
解释:struts2配置过滤器是用来执行分发功能的
4.拷贝Struts.xml文件以及相关的java文件和其他的xml配置文件
要粘贴到新建项目的src目录下,现在eclipse里面显示的是在Project Explorer中,如下,这里是无法显示src目录的
要切换到Package Explorer才能粘贴,切换方式有两种
1)Windows--> Show View-->Others 选择Java-->Package Explorer
2)在eclipse的右上角选择Java,如图:
切换之后就会看到src目录,把它们粘贴到这个目录即可
5.把struts-2.1.2-all\apps\struts2-blank-2.1.2下的example文件,和index.html拷贝到webContent目录下
到这里struts,就配置完成了,可以运行一下看看结果
6.运行struts项目:
1)编译项目,右键点击项目名称,选择build project(如果已经自动编译过,这步可省略)
2)配置Server-Tomcat
右键点击项目名称,选择debug as-->debug on
server
选择tomcat 5.5就行
点击finish即可看到结果。
选择Dynamic Web Project,然后next
2.输入项目名称,选择Target Runtime,点击new选择apache Tomcat 5.5,finish
3.添加strut2开发包,把下面的6个jar包拷贝到webContent/WEB-INF/lib里
commons-fileuploader-1.2.1.jar//好多介绍里没有引进这个包,不过这个貌似也要引进来,否则会提示Unable to load configuration. - bean - jar错误
commons-logging-1.0.4.jar
freemarker-2.3.12.jar
ognl-2.6.11.jar
struts2-core-2.1.2.jar
xwork-2.1.1.jar
拷贝完成后refresh,新加的jar包会显示到下图的位置
3.修改webContent/WEB-INF/web.xml,修改后的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
tutorial</display-name>//这里是你建立的工程的名字
<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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
解释:struts2配置过滤器是用来执行分发功能的
4.拷贝Struts.xml文件以及相关的java文件和其他的xml配置文件
要粘贴到新建项目的src目录下,现在eclipse里面显示的是在Project Explorer中,如下,这里是无法显示src目录的
要切换到Package Explorer才能粘贴,切换方式有两种
1)Windows--> Show View-->Others 选择Java-->Package Explorer
2)在eclipse的右上角选择Java,如图:
切换之后就会看到src目录,把它们粘贴到这个目录即可
5.把struts-2.1.2-all\apps\struts2-blank-2.1.2下的example文件,和index.html拷贝到webContent目录下
到这里struts,就配置完成了,可以运行一下看看结果
6.运行struts项目:
1)编译项目,右键点击项目名称,选择build project(如果已经自动编译过,这步可省略)
2)配置Server-Tomcat
右键点击项目名称,选择debug as-->debug on
server
选择tomcat 5.5就行
点击finish即可看到结果。
相关文章推荐
- 使用Eclipse配置Struts2开发环境
- 【转】Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- Struts2-03 eclipse怎么配置struts2支持,配置文件自动提示
- 基于Eclipse搭建SSH框架:第一篇 配置struts2
- eclipse下配置struts2,超详细!(包括war文件不能解压问题)
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- 在eclipse中进行Struts2项目的配置
- 在eclipse中配置Struts2
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- 在eclipse中进行Struts2项目的配置
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- 在Eclipse中配置Struts2
- eclipse下Struts2配置文件添加自动提示
- 在Eclipse中配置Struts2项目
- eclipse配置Struts2至Tomcat8.5 全过程搭建
- [转]Eclipse中配置Struts2并实现HelloWorld
- Eclipse下Struts2配置和Struts2处理流程