把字符流生成一个xml文件,然后在jsp里重定向,需要注意xsl的路径

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=gb2312" errorPage="systemerror.jsp" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="javax.xml.parsers.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="javax.xml.transform.*"%>
    <%@ page import="javax.xml.transform.stream.*"%>
    <%
          StringReader reader=new StringReader(你的xml);
          StreamSource xml = new StreamSource(reader);
          StreamSource xsl = new StreamSource(xsl文件路径);
           StreamResult result = new StreamResult(out);       Transformer trans = TransformerFactory.newInstance().newTransformer(xsl);
          //java.util.Properties properties = trans.getOutputProperties();
          //trans.setOutputProperty(OutputKeys.ENCODING,"GB2312");
          trans.setOutputProperty(OutputKeys.METHOD,"html");
          trans.setOutputProperty(OutputKeys.VERSION,"4.0");       
           //trans.setOutputProperty("encoding","UTF-8");
           trans.transform(xml, result);  %>
      

  2.   

    多谢两位,我先试一下。
    zhaoxichao(小西) 的方法可能和我的思路比较一致。
    我查阅其他资料的时候,看到其他人使用的是APACHE的一个TAGLIB库的方式解决这个问题,但是我没有在WEBLOGIC中调试成功,不知各位有没有这种解决的方案!!
    再次感谢各位!!
      

  3.   

    遇到一个棘手的问题:中文支持好像不太好!
    错误如下:java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence
    换成英文就一切OK!
    我把字符集转为GBK也不行!
    高人,指点一下!
      

  4.   

    加上trans.setOutputProperty("encoding","UTF-8");试试