zhouu 发表于 2017-1-23 06:09:42

eclipse中struts tomcat配置

1.安装Tomcat,增加服务器运行环境
Window-->Preferences-->Server-->Runtime Environment-->Add-->Apache-->选择Apache Tomcat v6.0-->next-->选择Tomcat安装根目录-->Finish

2.更改Java运行环境JRE,默认是jre6,这个只是运行环境,不包括调试,改成jdk1.6
Window-->Preferences-->Java-->Installed JREs-->Add-->选择 Standard VM-->Next-->选择JDK安装根目录-->Finish

3.在Eclipse中安装Tomcat插件,修改Preferences
Window-->Preferences-->Tomcat-->选择Tomcat版本和安装根目录-->Advanced-->选择Tomcat安装跟目录-->OK

4.新建Web项目(Dynamic Web Project),选择Target runtime-->Apache Tomcat v6.0。
 
5.解压struts-2.1.6,apps目录下解压struts2-blank-2.1.6.war;
 
6.复制struts-2.1.6\apps\struts2-blank-2.1.6\WEB-INF\lib目录下除junit-3.8.1.jar和spring-test-2.5.6.jar外的所有JAR包,到工程-->WEB-INF-->lib目录中。
 其中commons-io的jar包会在文件上传和下载时需要,其他为必须。
 
7.在package explorer视图中,复制struts2-blank-2.1.6\WEB-INF\src\java目录下的struts.xml到工程src目录下。
 
8.struts.xml中多余内容注释,把struts模式改成开发模式:<constant name="struts.devMode" value="true" />

<?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>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<include file="example.xml"/>

<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
-->
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello">
<result>
/hello.jsp
</result>
</action>
</package>
<!-- Add packages here -->
</struts>

[*]
9.在工程-->WEB-INF目录下,修改web.xml,添加filter和filter-mapping
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>MyStruts</display-name>
<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>
<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>
</web-app>
 10.新建jsp文件,hello.jsp,启动Tomcat,浏览器中输入http://localhost:8080/MyStruts/hello,查看效果!

其他配置:
 
1.建立struts2-core-2.16.jar文件对应的源码,以及对应Javadoc。
 选择struts2-core-2.16.jar属性,Java Source Attachment:struts-2.1.6/src/core/src/main/java;Javadoc Location:docs/struts2-core/apidocs/。
 
2.struts.xml不自动提示
 a)window – preferences – xml - xml catalog –> add 
 b)选择key type为URI
 c)key: http://struts.apache.org/dtds/struts-2.0.dtd
 d)location: 对应的dtd文件,位于struts-core包中,解压开,指定相应位置,如:struts-2.1.6\lib\struts2-core-2.1.6\struts-2.0.dtd
 
3.如果是复制的项目,需要修改 Content root
 
4.Tomcat的JVM也要选择 jdk1.6

页: [1]
查看完整版本: eclipse中struts tomcat配置