在eclipse中开发Struts2

本文介绍如何使用MyEclipse集成开发环境配置Tomcat服务器,并创建一个包含Struts2框架支持的基本Web应用程序。文章详细说明了配置过程,包括添加必要的类库、设置web.xml及struts.xml文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[align=center][b]创建web应用(使用MyEclipse)[/b][/align]

一、在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,运行应用程序
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值