创建web应用(使用MyEclipse)


一、在Eclipse整合Tomcat服务器

1、选择工作空间,打开Elcipse:Window->Preferences,将弹出界面

2、MyEclipse->Application Servers->Tomcat5 ,右边的界面发生变化,选中Enable,根据你的tomcat服务器的位置,其他选项依次是:

Tomcat 5
---------------------------------------------------------------
--Tomcat Server------------------------------------------------
| . Enable
| Disable
---------------------------------------------------------------
Tomcat Home Diretory E:\tomcat5.5
Tomcat Base Diretory E:\tomcat5.5
Tomcat Temp Arguments E:\tomcat5.5\temp
Optional Program Arguments

Restore Defaults Apply
---------------------------------------------------------------
OK Cancel
3、单击OK按钮,返回Eclipse主界面,即可。

二、新建web工程(略)

1、点击菜单File->New->Project,出现新对话框

2、选择 Web Project,点击“Next”,出现新对话框

3、在“Project Name”中键入Struts2_HelloWorld,单击finish

4、增加struts2支持,必须将Struts2框架的核心类库(struts2-core-2.0.11.jar、xwork-2.0.4.jar、ognl-2.6.11.jar、freemarker-2.3.8.jar、commons-logging-1.0.4.jar等)增加到web应用中(WEB-INF/lib),在eclipse中将这些jar文件加到工程的构建路径(build path)。

5、打开web.xml文件,将其修改为以下代码:
<?xml version="1.0" encoding="ISO-8859-1"?>
        <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"   "http://java.sun.com/dtd/web-app_2_3.dtd">
        <web-app>
                       <display-name>Struts 2.0 Hello World</display-name>
                       <!-- 定义Struts2的FilterDispathcer的Filter -->
                       <filter>
                                  <filter-name>struts2</filter-name>       
                                  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
                       </filter>
                         <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
                       <filter-mapping>
                                         <filter-name>struts2</filter-name>
                                        <url-pattern>/*</url-pattern>
                       </filter-mapping>
                         <welcome-file-list>
                                <welcome-file>index.html</welcome-file>
                       </welcome-file-list>
         </web-app>

6、新建struts.xml文件 ,添加到src路径下(即web应用中的classes/),然后将struts.xml的内容修改为:
             <!DOCTYPE struts PUBLIC
           "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
           "http://struts.apache.org/dtds/struts-2.0.dtd">
       <struts>
               <include file="struts-default.xml"/>
       </struts>  

7、新建index.html文件


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
        <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
               <title>Hello World</title>
        </head>
          <body>
            <h3>Hello World!</h3>
          </body>
      </html>

8、将应用程序打包到tomcat上
9、启动tomcat,运行应用程序
评论
发表评论

您还没有登录,请登录后发表评论