servlet中显示中文的问题

hellohong1997 2003-04-02 07:17:57
如何在servlet中显示中文,我用的服务器是weblgic
res.setContentType("text/html; Charset=gb2312");
好象不行!
难道是weblogic不支持中文?
...全文
28 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
truezerg 2003-05-24
大哥们~~~~~~~~~~~~~~~~~~~~~~~~~~
回复
wanggangytsoft 2003-05-24
给你一个转换函数
public static String toGBK(String as_str)
{
try
{
byte[] szbuf = as_str.getBytes("8859_1");
return new String(szbuf, "GBK");
} catch(Exception e)
{
}
return null;
}
回复
sandwish2000 2003-05-24
我解决了!
大家看看!
不过要给我分哦!
呵呵!

import javax.servlet.*;
import java.io.*;


public class Myserver extends GenericServlet{
public void service(ServletRequest request,ServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();

pw.println("<%@ page contentType='text/html;charset=GB2312' %>");
//pw.println("<%response.setContentType('text/html;charset=GB2312');%>");
//System.out.println("<B>妈妈最最喜欢吃的东西:</B>");
pw.println("<html>");
pw.println("<body>");
pw.println("<center>");
pw.println("<form name='Form1' method='post' action='http://localhost:8080/servlet/Myserver'>");
pw.println("<B>");
try{
pw.println(new String((new String("妈妈最最喜欢吃的东西:")).getBytes("GBK"),"ISO8859_1"));
pw.println("</B>");
pw.println("<select name='favourate' size='1'>");
pw.println("<option value='xiangjiao'>" + new String((new String("香蕉")).getBytes("GBK"),"ISO8859_1") + "</option>");
pw.println("<option value='xiangjiao'>" + new String((new String("苹果")).getBytes("GBK"),"ISO8859_1") + "</option>");
pw.println("<option value='xiangjiao'>" + new String((new String("山楂")).getBytes("GBK"),"ISO8859_1") + "</option>");
pw.println("<option value='xiangjiao'>" + new String((new String("巧克力")).getBytes("GBK"),"ISO8859_1") + "</option>");
pw.println("<option value='xiangjiao'>" + new String((new String("其他")).getBytes("GBK"),"ISO8859_1") + "</option>");
}
catch( UnsupportedEncodingException e)
{
}

//try{
// pw.println(new String((new String("妈妈最最喜欢吃的东西:")).getBytes("GBK"),"ISO8859_1"));
//
// }
// catch( UnsupportedEncodingException e)
// {
// }
//pw.println("<option value='xiangjiao'>香蕉</option>");
//pw.println("<option value='pingguo'>苹果</option>");
//pw.println("<option value='shanzha'>山楂</option>");
//pw.println("<option value='qiaokeli'>巧克力</option>");
//pw.println("<option value='qita'>其他</option>");
pw.println("</select>");
pw.println("<br><br>");
pw.println("<input type=submit value='Submit'>");
pw.println("</form></body></html>");
pw.close();
}


}
//<%@ page contentType="text/html;charset=iso8859_1"%>
//<%response.setContentType("text/html;charset=iso8859_1");%>
/*
try{
out.println(new ( (new String("我爱死你了")).getBytes("GBK"),"ISO8859_1"))
}
catch( UnsupportedEncodingException e)
{
}

*/
回复
sandwish2000 2003-05-24
我的System.out.println()正常!
可是
import javax.servlet.*;
import java.io.*;


public class Myserver extends GenericServlet{
public void service(ServletRequest request,ServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();

pw.println("<%@ page contentType='text/html;charset=GB2312' %>");
//pw.println("<%response.setContentType('text/html;charset=GB2312');%>");
System.out.println("<B>妈妈最最喜欢吃的东西:</B>");
pw.println("<html>");
pw.println("<body>");
pw.println("<center>");
pw.println("<form name='Form1' method='post' action='http://localhost:8080/servlet/Myserver'>");
pw.println("<B>妈妈最最喜欢吃的东西:</B>");
pw.println("<select name='favourate' size='1'>");
pw.println("<option value='xiangjiao'>香蕉</option>");
pw.println("<option value='pingguo'>苹果</option>");
pw.println("<option value='shanzha'>山楂</option>");
pw.println("<option value='qiaokeli'>巧克力</option>");
pw.println("<option value='qita'>其他</option>");
pw.println("</select>");
pw.println("<br><br>");
pw.println("<input type=submit value='Submit'>");
pw.println("</form></body></html>");
pw.close();
}


}
//<%@ page contentType="text/html;charset=iso8859_1"%>
//<%response.setContentType("text/html;charset=iso8859_1");%>

就有问题!
回复
sandwish2000 2003-05-24
顶!我也是!
回复
stevene 2003-04-02
你在servlet中用System.out.println()输出能不能正常显示?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-02 07:17
社区公告
暂无公告