© 版权声明:本文为博主原创文章,转载请注明出处

Struts2后缀

  - Struts2默认后缀是action

  - Struts2使用默认后缀时*.action和*都是同一个请求

  - Struts2自定义后缀后只能使用自定义的后缀访问(eg.*.c和*不再是同一个请求)

  - Struts2自定义后缀方式

    - 方式一:在struts.xml中配置struts.action.extension常量

    - 方式二:在web.xml中配置struts.action.extension

    - 方式三:在struts.properties中配置struts.action.extension

实例

1.项目结构

2.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.struts</groupId>
<artifactId>Struts2-CustomSuffix</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Struts2-CustomSuffix Maven Webapp</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<struts.version>2.5.10</struts.version>
</properties> <dependencies>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
</dependency>
</dependencies> <build>
<finalName>Struts2-CustomSuffix</finalName>
</build> </project>

3.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
version="3.0" metadata-complete="true"> <!-- struts2过滤器 -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 方式二 -->
<!-- <init-param>
<param-name>struts.action.extension</param-name>
<param-value>cc</param-value>
</init-param> -->
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

4.HelloAction.java

package org.struts.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Override
public String execute() throws Exception { return SUCCESS; } }

5.struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts> <package name="hello" extends="struts-default" namespace="/">
<action name="hello" class="org.struts.action.HelloAction">
<result>/index.jsp</result>
</action>
</package> <!-- 方式一 -->
<constant name="struts.action.extension" value="c"/> </struts>

6.struts.properties

#指定action后缀(方式三)
#struts.action.extension=ccc

7.index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index.jsp</title>
</head>
<body>
访问成功了。。。
</body>
</html>

8.效果预览

  8.1 方式一

  

  8.2 方式二

  

  8.3 方式三

  

参考:http://www.imooc.com/video/9002

Struts2学习七----------Struts2后缀的更多相关文章

  1. Struts2学习一----------Struts2的工作原理及HelloWorld简单实现

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...

  2. Struts2入门(七)——Struts2的文件上传和下载

    一.前言 在之前的随笔之中,我们已经了解Java通过上传组件来实现上传和下载,这次我们来了解Struts2的上传和下载. 注意:文件上传时,我们需要将表单提交方式设置为"POST" ...

  3. Struts2学习笔记--Struts2的体系结构

    1. Struts2体系结构 Struts是以前端控制器框架为主体的框架,用户的请求会通过控制器选择不同的Action类来执行具体的操作,在Action类中所有的Servlet对象(request.r ...

  4. Struts2学习笔记——Struts2与Spring整合

      Struts2与Spring整合后,可以使用Spring的配置文件applicationContext.xml来描述依赖关系,在Struts2的配置文件struts.xml来使用Spring创建的 ...

  5. struts2学习(2)struts2核心知识

    一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...

  6. struts2学习(1)struts2 helloWorld

    一.struts2简介: 二.helloWorld: 1)工程结构: HelloWorldAction.java: package com.cy.action; import com.opensymp ...

  7. struts2学习(15)struts2防重复提交

    一.重复提交的例子: 模拟一种情况,存在延时啊,系统比较繁忙啊啥的. 模拟延迟5s钟,用户点了一次提交,又点了一次提交,例子中模拟这种情况: 这样会造成重复提交:   com.cy.action.St ...

  8. struts2学习(14)struts2文件上传和下载(4)多个文件上传和下载

    四.多个文件上传: 五.struts2文件下载: 多个文件上传action com.cy.action.FilesUploadAction.java: package com.cy.action; i ...

  9. struts2学习(13)struts2文件上传和下载(1)

    一.Struts2文件上传: 二.配置文件的大小以及允许上传的文件类型: 三.大文件上传: 如果不配置上传文件的大小,struts2默认允许上传文件最大为2M: 2097152Byte:   例子实现 ...

随机推荐

  1. docker 集群 flannel网络构建

    先保证集群状态是正常的 集群管理 kubelet 在创建pod 时会先下载一个pause 镜像,这个镜像用于容器基础网络管理非常重要: 每个node 节点都要执行该操作: iptables -P FO ...

  2. [暑假集训--数论]hdu1019 Least Common Multiple

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

  3. 模板jinja2常用方法

    http://docs.jinkan.org/docs/jinja2/ 摘自 http://www.pythontip.com/blog/post/5455/ 数学运算       +, -, *,  ...

  4. c language compile process.

  5. WebStorm使用JetBrains IDE Support调试

    1.安装WebStorm 2.安装谷歌的chome浏览器,并切换到开发者模式 3.下载并安装 JetBrains IDE Support(将2.0.7_0.crx文件直接拖到谷歌浏览器中就会自动安装) ...

  6. 归并排序Merge sort(转)

    原理,把原始数组分成若干子数组,对每一个子数组进行排序, 继续把子数组与子数组合并,合并后仍然有序,直到全部合并完,形成有序的数组 举例 无序数组[6 2 4 1 5 9] 先看一下每个步骤下的状态, ...

  7. linux2.4内核调度

    进程调度需要兼顾3种进程:交互进程,批处理进程,实时进程,在设计一个进程调度机制时需要考虑具体问题 (1)调度时机? 答:进程在用户空间可以pause()或者让内核设置进程为睡眠状态,以此调度,调度还 ...

  8. OpenMP参考链接

    做个笔记. http://www.cnblogs.com/China3S/p/3500507.html

  9. iptables之centos6版本详解

    1 Linux防火墙概述 Linux防火墙实际指的是Linux下的Netfilter/Iptables.Netfilter/Iptables是2.4.x/2.6.x版本Linux内核集成的IP信息包过 ...

  10. hdu 4524(模拟)

    郑厂长系列故事——逃离迷宫 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...