Struts2 配置文件struts.xml详解

我们先来看一段struts.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>

	<package name="hello" namespace="/hello" extends="struts-default">
		<action name="hellAction" class="com.sunday.action.HelloAction"  method="hello">
			<result name="success" >/hello.jsp</result>
		</action>
	</package>
	<!-- 引入其他struts配置文件 -->
	<include file="com/sunday/action/struts.xml"></include>
	<include file="com/sunday/action/dynamic/struts.xml"></include>
	<include file="com/sunday/defaultAction/struts.xml"></include>

</struts>  

下面我们来详细讲解下struts.xml

  • 导入约束

查看sturts2-core-xxx.jar中struts-default.xml文件

  复制如下代码到我们新建的struts.xml中

  

 

  • 元素详解
    <!-- package:将Action配置封装.就是可以在Package中配置很多action.
            name属性: 给包起个名字,起到标识作用.随便起.不能其他包名重复.
            namespace属性:给action的访问路径中定义一个命名空间
            extends属性: 继承一个 指定包
            abstract属性:包是否为抽象的; 标识性属性.标识该包不能独立运行.专门被继承
      -->
    <package name="hello" namespace="/hello" extends="struts-default" >
        <!-- action元素:配置action类
                name属性: 决定了Action访问资源名.
                class属性: action的完整类名
                method属性: 指定调用Action中的哪个方法来处理请求
         -->
        <action name="HelloAction" class="cn.itheima.a_hello.HelloAction" method="hello" >
            <!-- result元素:结果配置
                    name属性: 标识结果处理的名称.与action方法的返回值对应.
                    type属性: 指定调用哪一个result类来处理结果,默认使用转发.
                    标签体:填写页面的相对路径
            -->
            <result name="success" type="dispatcher" >/hello.jsp</result>
        </action>
    </package>
  • 引入其他配置文件
    <!-- 引入其他struts配置文件 -->
    <include file="com/sunday/action/struts.xml"></include>    

原文地址:https://www.cnblogs.com/sharp367/p/9957347.html

时间: 2024-07-29 01:34:45

Struts2 配置文件struts.xml详解的相关文章

Struts2初学 Struts.xml详解二

A.使用继承实现设置全局视图    package节点中还可以设置全局的视图,如:     <global-results>         <result name="err">/err.jsp</result> </global-results> 但如果其他包也想实现这样的视图,就需要使用继承的方式实现,如: <package name="base" namespace="" extend

Tomcat主配置文件Server.xml详解

Tomcat主配置文件Server.xml详解 1.软件版本 [[email protected] META-INF]# java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) 2.server.xml组件类别 顶级组件:位于整个配置的

JavaEE学习之Maven配置文件pom.xml详解(转)

一.引言 (本文转载自:http://blog.csdn.net/longeremmy/article/details/9670619) 使用maven有一些时间了,一直没有好好将pom配置文件每个节点的意义好好了解一番.今天突然想来了解下:pom- project object model 项目对象模型.顾名思义,他是用来描述项目信息的,以及构建方式,依赖等.网上有一篇文章写的很详细,这里就借用一下,以备日后使用. 二.详解 1 <project xmlns="http://maven.

struts2配置文件struts.xml的目录问题

struts2的配置文件struts.xml默认是直接在src目录下.这样我们在部署描述符web.xml中,指定struts2的过滤器时,直接如 清单一: <filter>   <filter-name>struts2</filter-name>   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  </filter>  <f

maven全局配置文件settings.xml详解

maven全局配置文件settings.xml详解 https://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension 各种标签说明,没有<distributionManagement> 原文地址:https://www.cnblogs.com/stono/p/9456886.html

(2) tomcat配置文件server.xml详解

1. 入门示例:虚拟主机提供web服务 该示例通过设置虚拟主机来提供web服务,因为是入门示例,所以设置极其简单,只需修改$CATALINA_HOME/conf/server.xml文件为如下内容即可,本文的tomcat安装在/application/tomcat下,因此$CATALINA_HOME=/application/tomcat. 其中大部分都采用了默认设置,只是在engine容器中添加了两个Host容器. <?xml version="1.0" encoding=&q

struts2总结三:struts2配置文件struts.xml的简单总结

一.struts中的常量constant的配置,在struts2中同一个常量的配置有三种方式,第一种在struts.xml中,第二种在struts.properties中配置,第三种在web.xml中配置. 以配置struts2为开发模式为例: 1.在struts.xml中配置 <constant name="struts.devMode" value="true"></constant> 2.在struts.properties中配置 st

struts.xml详解

参考自:http://blog.csdn.net/zz_mm/article/details/5460397 1.    深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1.    包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管理Action和拦截器等.每个包就是多个Action.多个拦截器.多个拦截器引用的集合. 在struts.xml文件中package元素用于定义包配置,每个package元素定义了一个包配置

omcat配置文件server.xml详解

首先,看一下tomcat的目录结构: bin            存放启动和关闭tomcat脚本 conf          包含不同的配置文件,server.xml(Tomcat的主要配置文件)和web.xml work          存放jsp编译后产生的class文件 webapp     存放应用程序示例,以后你要部署的应用程序也要放到此目录 logs           存放日志文件 lib/japser/common    这三个目录主要存放tomcat所需的jar文件 ---