---
title: "struts2 配置json"
author: "haige18"
date: "2010-10-27T21:26:28Z"
tags: ["Apache", "Struts", "Web", "XML", "json"]
categories: ["企业架构"]
slug: "struts2-json"
draft: false
lastmod: "2010-10-27T21:26:46Z"
id: 795934
url: "https://haige18.iteye.com/blog/795934"
---

一、导入所需包，包括Struts2所需的各jar包，再导入struts2-convention-plugin-2.1.jar和jsonplugin-0.34.jar

 JSON Plugin，它可以将Struts2 Action中的结果直接返回为JSON。下载地址：[http://jsonplugin.googlecode.com/files/jsonplugin-0.34.jar](http://jsonplugin.googlecode.com/files/jsonplugin-0.34.jar) （支持struts2.1.6及以上版本）。

二、在Web.xml添加Struts2

 

web.xml

 

```
<filter>   
        <filter-name>struts2</filter-name>   
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>   
    </filter>   
    <filter-mapping>   
        <filter-name>struts2</filter-name>   
        <url-pattern>/*</url-pattern>   
    </filter-mapping>   
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
```

 

 

三、修改struts.xml，配置struts2-convention-plugin。并修改convention-plugin默认的结果资源路径为webroot/

 

struts.xml

 

```
<struts>   
   
    <!-- 结果资源所在路径 -->      
    <constant name="struts.convention.result.path" value="/"/>   
   
</struts> 
```

 

 

 

来自：[http://blog.sina.com.cn/s/blog\_6145ed810100h5q2.html](http://blog.sina.com.cn/s/blog_6145ed810100h5q2.html)