linlinyu

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

          struts2 輸出xml格式內容

          Posted on 2007-12-20 23:04 linlin yu 閱讀(1815) 評論(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
          多謝了,挺有用的。

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


          網站導航:
           
          主站蜘蛛池模板: 邵武市| 思茅市| 富顺县| 永寿县| 奉节县| 兴安县| 张家口市| 鄯善县| 扎鲁特旗| 封丘县| 廊坊市| 枞阳县| 耒阳市| 本溪| 雷山县| 香格里拉县| 中卫市| 杂多县| 五家渠市| 东兰县| 长乐市| 辽宁省| 永宁县| 醴陵市| 随州市| 五大连池市| 镶黄旗| 双峰县| 翁牛特旗| 尉犁县| 威海市| 寿阳县| 封开县| 荃湾区| 三门县| 株洲县| 子洲县| 井陉县| 邯郸市| 正蓝旗| 辽宁省|