本篇文章以现在最新的
struts 2.3.1.2为例。
//首先必不可少的当然是导入jar包
commons-fileupload-1.2.2.jar,commons-io-2.0.1.jar,
commons-lang-2.5.jar, commons-logging-1.1.1.jar, freemarker-2.3.18.jar, javassist-3.11.0.GA.jar, ognl-3.0.4.jar, struts2-core-2.3.1.2.jar, xwork-core-2.3.1.2.jar
//1>首先要在web.xml中进行配置
<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>
//2>在src目录下新建struts.xml配置文件,并进行配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
//注:package 中的name这个可以随便起,extends属性值必须为struts-default
//action 的name属性就是你自己命名了,后面的class属性是代表该action所对应的类的完
//全限定名,
<package name="myPackage" extends="struts-default">
<action name="hello" class="com.hx.web.HelloAction">
//result的name属性默认为"success",另外result还有4个常用的type属性:(默认
//为dispatcher)
//1.chain→请求转发到action,2.dispatcher→请求转发到jsp,3.redirect→重定向
//到jsp,4.redirectAction→重定向到action
<result>hello.jsp</result>
</action>
</package>
</struts>
//3>新建一个类,HelloAction
public class HelloAction {
public String execute(){
System.out.println("struts2 runing");
return "success";
}
//4>地址栏输入localhost:port/项目名/hello.action
控制台输出结果:struts2 runing说明该struts项目配置成功!
}
这一篇就说到这里,另外我想说的是:我们既可以在 Action 中定义异常与结果,也可以定义全局的异常与结果,
局部总是优于全局的,如果定义成全局,那么可以为所有Action 所公用,而局部的异常与结果只能被当前的Action 所独享,不能为其他Action 所共享。下一篇将给大家介绍action的进一步配置-method属性的配置,以及如何在action中调用指定的方法。
分享到:
相关推荐
struts-config.xml struts标准配置文件 struts-config
快速配置Struts2环境 4. 开发一个Struts2简单实例 5. struts.xml文件 三. Struts2深入开发 6. 常用标签配置和使用 7. 常用标签配置和使用 8. 标签 9. Action类的开发 10. 数据类型转换器 11. 实现...
The org.apache.struts2.config.Configuration implementation class org.apache.struts2.config.Configuration接口名 struts.configuration.files A list of configuration files automatically loaded by ...
3.Struts 2权威指南——第3章 Struts 2基础.doc 4.Struts2.0系列(1-15) 5.Struts2中用Spring实现IoC.doc 6.Struts2中的零配置与CoC(Convention over Configration).doc 7.Struts2介绍之使用链接标签.doc 8.Struts2...
struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...
浪曦_Struts2应用开发系列_第1讲.Struts2入门与配置_swf
struts2 配置dtd 自动提示 struts2 配置dtd 自动提示
·Struts2配置文件介绍 struts.xml action package ·Struts2配置文件介绍 struts.xml action package
浪曦_Struts2应用开发系列_第1讲.Struts2入门与配置2
NULL 博文链接:https://8366.iteye.com/blog/415329
struts2 使用注解现在零配置不需要在使用struts.xml配置文件。 struts2 注解实例。可以直接跑
Struts框架中struts-config.xml文件配置小结
浪曦_Struts2应用开发系列_第1讲.Struts2入门与配置
SSH(Struts,Spring,Hibernate)struts.xml文件配置
Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解,Struts2配置详解
3.初识struts2配置文件 4 (1).web.xml文件 4 (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-default.xml 4 (5)其它配置文件 4 4.让MyEclipse提示xml信息 4 5.如何...
struts2配置过滤器 示例代码
3、struts2配置文件 4、cion主要内容 Namespace、自定义Action、路径问题、通配符、包含模块配置文件、默认Action、接受用户输入、服务器跳转、Action中访问web元素、简单数据校验、调用Action的自定义方法 5...
针对Struts2.5.2最新版本的配置进行了梳理,通过一步步的步骤和发生的问题点的解决,完成对Struts2.5.2的配置。
3、Struts1 的验证逻辑编写在 ActionForm 中; Struts2 中的验证逻辑编写在 Action 中. 4、Struts1 中, Action 类必须继承 org.apache.struts.action.Action 类; Struts2 中任何一个 POJO 都可以是一个 Action 类. 5...