问一个Axis的中文问题

hongliang13 2004-05-08 09:52:33
一个简单的Hello.jws如下:
public class Hello
{
public String hello(String name)
{
if(name==null)
name = "";
return "你好"+name+",欢迎来到Web服务的世界!";
}
}

本机调用http://localhost:8080/axis/Hello.jws?method=hello,得到以下结果(中文都成了? :():

<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <helloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<helloReturn xsi:type="xsd:string">???????Web??????</helloReturn>
</helloResponse>
</soapenv:Body>
</soapenv:Envelope>

如果传入中文参数(http://localhost:8080/axis/Hello.jws?method=hello&name=路人甲),还会得到这个错误
<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence.</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

小弟初学Axis,还望各位大侠多多帮助:)
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovezn0424 2004-05-10
  • 打赏
  • 举报
回复
public class Hello
{
public String hello(String name)
{
if(name==null)
name = "";
String result = "";
try{
result = new
String
(("你好"+name+",迎来到Web服务的世界!").getBytes("ISO8859-1"),"UTF8");
}
catch(java.io.UnsupportedEncodingException e)
{}
return result;

}
}

hongliang13 2004-05-09
  • 打赏
  • 举报
回复
up
hongliang13 2004-05-08
  • 打赏
  • 举报
回复
关注?老大,帮帮忙阿!!!
minghuitian 2004-05-08
  • 打赏
  • 举报
回复
gz

67,515

社区成员

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

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