急切求助:xml+xsl做表单提交,乱码问题!!

eesen 2005-08-29 03:41:46
用xml+xs做表单l提交,数据到提交到struts的action,生成新的xml文件是乱码(在IDEA中的Debug下看到的编码有2种格式:ISO 和UTF8),请问:这种问题如何解决?谢谢!
在线等待!!!!

...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinwuhanqqm 2005-10-16
  • 打赏
  • 举报
回复
谢谢!
rower203 2005-08-29
  • 打赏
  • 举报
回复
帮(小猫咪) 顶一下。
xinwuhanqqm 2005-08-29
  • 打赏
  • 举报
回复
自己先顶一下!!!谢谢支持:)

对上述问题的补充(问题描述)

test.xml + text.xsl,提交表单数据到servlet,servlet打印提交的字符串是乱码,以下是源代码:

test.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<body>
</body>

test.xsl
--------------------------------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body>
<form name="form1" action="/Test">

<xsl:element name="input">
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="name">property</xsl:attribute>
<xsl:attribute name="value">
</xsl:attribute>
</xsl:element>

<input type="submit" value="submit"/>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

servlet(Test)
---------------------------------------------------------------------
package eesen;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
* Created by IntelliJ IDEA.
* User: ut28
* Date: 2005-8-29
* Time: 14:31:47
* To change this template use File | Settings | File Templates.
*/

public class Test extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
getTestSubmit(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
getTestSubmit(request,response);
}

public void getTestSubmit(HttpServletRequest request, HttpServletResponse response){
try {
PrintWriter out=response.getWriter();
String str=request.getParameter("property");
out.println(toGB2312(str));
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
public String toGB2312(String str){
String strTemp="";
try {
strTemp=new String(str.getBytes("ISO8859_1"),"GB2312");
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return strTemp;
}
}

web.xml
--------------------------------------------------------------------------
<web-app>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>eesen.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
</web-app>

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧