1,配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="example" namespace="/example"
extends="struts-default">
<action name="outputXml" method="outxml" class="example.OutputXml">
<result name="xmlMessage" type="plaintext"></result>
</action>
</package>
</struts>
2,java代碼
package example;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class OutputXml extends ActionSupport {
public void outxml() throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/xml ");
PrintWriter pw = response.getWriter();
pw.print("<cc>cccccc</cc>");
}
}












2,java代碼

















