---
title: "Struts2后缀-深入Struts2"
author: "cakin24"
date: "2017-10-21T07:44:44Z"
tags: []
categories: ["编程语言"]
slug: "struts2-struts2"
draft: false
lastmod: "2017-10-21T07:44:44Z"
id: 2397141
url: "https://cakin24.iteye.com/blog/2397141"
---

一 将action后缀变成html后缀

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;

&lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "[http://struts.apache.org/dtds/struts-2.1.dtd"](http://struts.apache.org/dtds/struts-2.1.dtd%22);&gt;

&lt;struts&gt;

        &lt;include file="helloworld.xml"&gt;&lt;/include&gt;

        &lt;constant name="struts.action.extension" value="html"&gt;&lt;/constant&gt;

        &lt;constant name="struts.enable.DynamicMethodInvocation" value="false"&gt;&lt;/constant&gt;

&lt;/struts&gt; 

 

二 测试

![](http://dl2.iteye.com/upload/attachment/0127/4724/e0ef44ec-3d22-3ba7-a918-2df8df6b2106.png)  
 

 

三 去掉action后缀

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;

&lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "[http://struts.apache.org/dtds/struts-2.1.dtd"](http://struts.apache.org/dtds/struts-2.1.dtd%22);&gt;

&lt;struts&gt;

        &lt;include file="helloworld.xml"&gt;&lt;/include&gt;

        &lt;!-- 如果不配置下面这句话，也可以去掉后缀访问--&gt;

        &lt;constant name="struts.action.extension" value=""&gt;&lt;/constant&gt;

        &lt;constant name="struts.enable.DynamicMethodInvocation" value="false"&gt;&lt;/constant&gt;

&lt;/struts&gt;

 

四 测试

![](http://dl2.iteye.com/upload/attachment/0127/4726/abb99eac-5fe3-3885-9db4-09d728f717d3.png)  
 

 

五 配置后缀的三种方式

1、在struts.xml中配置

&lt;constant name="struts.action.extension" value="html"&gt;&lt;/constant&gt;

2、在struts.properties中配置,而且可以配置多个后缀

struts.action.extension=action,do,struts2,

3、在web.xml中配置

 

![](http://dl2.iteye.com/upload/attachment/0127/4728/a0a7e89b-f417-3b39-9283-e74533f560a6.png)