structs2.3.4 学习笔记
1.在myeclipse7.0中创建web project项目
2.添加 struts2.3.4 所需要的lib文件,具体要用到的jar文件如下:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.4.jar
xwork-core-2.3.4.jar
3.修改web.xml文件,在web.xml中添加如下内容(黑色字体的内容)
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.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>
4.在src 目录下添加structs.xml文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.devMode" value="true" /> <!-- 设置开发模式 --> <constant name="struts.action.extension" value="action,do"></constant> <package name="default" namespace="/" extends="struts-default"> <!-- <action name="hello" class=""> --> <action name="hello"> <!-- 定义逻辑视图和物理资源之间的映射 --> <!-- <result name="input">/index.jsp</result> --> <result>index.jsp</result> </action> </package> </struts>
5. 把文件部署到服务器,然后在浏览器中输入:http://localhost:8080/buy360/hello.action (因我所做的实验,项目名称与web-context root:buy360), 最后浏览器中显示 : This is my jsp 表示struct 流程运行成功
本文介绍如何在MyEclipse 7.0环境中搭建Struts2.3.4框架,包括所需库文件配置、web.xml及struts.xml文件的编写,并演示了一个简单的示例程序。
6041

被折叠的 条评论
为什么被折叠?



