linlinyu

          linlinyu
          posts - 0, comments - 4, trackbacks - 0, articles - 15

          struts2 輸出xml格式內容

          Posted on 2007-12-20 23:04 linlin yu 閱讀(1814) 評論(1)  編輯  收藏 所屬分類: java
          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>");
              }

          }

          Feedback

          # re: struts2 輸出xml格式內容  回復  更多評論   

          2009-09-14 11:55 by lw
          多謝了,挺有用的。

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 康平县| 隆子县| 松潘县| 肇东市| 富锦市| 天全县| 桂东县| 融水| 定远县| 景谷| 东平县| 红安县| 永仁县| 双牌县| 奉贤区| 巩义市| 建宁县| 呼玛县| 灵石县| 朝阳区| 昆明市| 武夷山市| 武平县| 德令哈市| 瑞丽市| 顺昌县| 特克斯县| 揭西县| 鄂尔多斯市| 井陉县| 武穴市| 丽江市| 光泽县| 南召县| 青浦区| 湖北省| 久治县| 石林| 巴林右旗| 福建省| 莒南县|