社区
Web 开发
帖子详情
求Servlet的乱码解决办法!
liuwenxian
2004-10-22 12:45:29
各位兄弟姐妹能不能介绍一下你们都是怎么处理Servlet的乱码的呀,小弟我都为了这个问题烦恼了好几天了······救命啊!!!
...全文
241
2
打赏
收藏
求Servlet的乱码解决办法!
各位兄弟姐妹能不能介绍一下你们都是怎么处理Servlet的乱码的呀,小弟我都为了这个问题烦恼了好几天了······救命啊!!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
liuwenxian
2004-10-23
打赏
举报
回复
我的SERVLET代码就是这样的,不知道为什么从数据库读出的数据都是乱吗“??”
,有人有处理的办法么?我用的是Tomcat5.26!!!!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ShareSelect extends HttpServlet{
Connection con=null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
//加载桥接器
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
}
}
public String getcode(String s){
String str=s;
try{
str=new String(str.getBytes("iso-8859-1"),"GB2312");
return str;
}
catch(Exception e){
str="111111";
return str;
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
PrintWriter out=response.getWriter();
request.setCharacterEncoding("iso-8859-1");
response.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
out.println("<html>");
out.println("<body>");
Statement sql=null;
ResultSet rs=null;
String str1,str2,str3,str4,str5,str6,str7,str8,str9;
if(con==null){
try{
con=DriverManager.getConnection("jdbc:odbc:renshi","sa","");
sql=con.createStatement();
rs=sql.executeQuery("select * from jihualuyong ");
out.print("<table>");
out.print("<tr>");
out.print("<th width=100>"+"人员代码");
out.print("<th width=100>"+"人员姓名");
out.print("<th width=100>"+"人员性别");
out.print("<th width=100>"+"真实年龄");
out.print("<th width=100>"+"最高学历");
out.print("<th width=200>"+"个人简述");
out.print("<th width=100>"+"申请职位");
out.print("<th width=100>"+"家庭住址");
out.print("<th width=100>"+"联系电话");
out.print("</tr>");
while(rs.next()){
str1=rs.getString(1);
str1=getcode(str1);
str2=rs.getString(2);
str2=getcode(str2);
str3=rs.getString(3);
str3=getcode(str3);
str4=rs.getString(4);
str4=getcode(str4);
str5=rs.getString(5);
str5=getcode(str5);
str6=rs.getString(6);
str6=getcode(str6);
str7=rs.getString(7);
str7=getcode(str7);
str8=rs.getString(8);
str8=getcode(str8);
str9=rs.getString(9);
str9=getcode(str9);
out.print("<tr>");
out.print("<td>"+str1+"</td>");
out.print("<td>"+str2+"</td>");
out.print("<td>"+str3+"</td>");
out.print("<td>"+str4+"</td>");
out.print("<td>"+str5+"</td>");
out.print("<td>"+str6+"</td>");
out.print("<td>"+str7+"</td>");
out.print("<td>"+str8+"</td>");
out.print("<td>"+str9+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
catch(SQLException e){
}
}
else{
synchronized(con){
try{
sql=con.createStatement();
rs=sql.executeQuery("select * from jihualuyong");
out.print("<table>");
out.print("<tr>");
out.print("<th width=100>"+"人员代码");
out.print("<th width=100>"+"人员姓名");
out.print("<th width=100>"+"人员性别");
out.print("<th width=100>"+"真实年龄");
out.print("<th width=100>"+"最高学历");
out.print("<th width=200>"+"个人简述");
out.print("<th width=100>"+"申请职位");
out.print("<th width=100>"+"家庭住址");
out.print("<th width=100>"+"联系电话");
out.print("</tr>");
while(rs.next()){
str1=rs.getString(1);
str1=getcode(str1);
str2=rs.getString(2);
str2=getcode(str2);
str3=rs.getString(3);
str3=getcode(str3);
str4=rs.getString(4);
str4=getcode(str4);
str5=rs.getString(5);
str5=getcode(str5);
str6=rs.getString(6);
str6=getcode(str6);
str7=rs.getString(7);
str7=getcode(str7);
str8=rs.getString(8);
str8=getcode(str8);
str9=rs.getString(9);
str9=getcode(str9);
out.print("<tr>");
out.print("<td>"+str1+"</td>");
out.print("<td>"+str2+"</td>");
out.print("<td>"+str3+"</td>");
out.print("<td>"+str4+"</td>");
out.print("<td>"+str5+"</td>");
out.print("<td>"+str6+"</td>");
out.print("<td>"+str7+"</td>");
out.print("<td>"+str8+"</td>");
out.print("<td>"+str9+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
catch(SQLException e){
}
}
}
out.print("</body>");
out.print("</html>");
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
doPost(request,response);
}
}
mhz
2004-10-22
打赏
举报
回复
你能不能说清楚?
拜托!!!
servlet
乱码
及解决
这是
servlet
出现
乱码
,以及
乱码
出现时的
解决办法
。
Servlet
页面输出中文
乱码
解决办法
Servlet
页面输出中文
乱码
解决办法
解决
Servlet
中文
乱码
问题
一、出现
乱码
的原因 由于浏览器默认使用UTF-8码表进行编码,而
servlet
使用ISO-8859-1码表进行编码,传输和接收方编码不一致导致
乱码
的产生。中文
乱码
就是因为编码不符,可能出现
乱码
有四个地方: 1 JSP编码
乱码
2 HTML编码
乱码
3 request获取数据
乱码
4 response输出信息
乱码
二、
乱码
的类型以及
解决办法
1、Html中文
乱码
问题。 ...
Servlet
添加数据到Mysql中文
乱码
解决办法
Servlet
添加数据到Mysql中文
乱码
解决办法
,
Servlet
乱码
,mysql
乱码
,jsp页面
乱码
,html页面
乱码
java
servlet
中文
乱码
_
Servlet
中文
乱码
问题解决方案解析
一、出现
乱码
的原因由于浏览器默认使用UTF-8码表进行编码,而
servlet
使用ISO-8859-1码表进行编码,传输和接收方编码不一致导致
乱码
的产生。二、
乱码
的类型以及
解决办法
1、 response
乱码
一、出现
乱码
的原因由于浏览器默认使用UTF-8码表进行编码,而
servlet
使用ISO-8859-1码表进行编码,传输和接收方编码不一致导致
乱码
的产生。二、
乱码
的类型以及
解决办法
1、 respon...
Web 开发
81,114
社区成员
341,728
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章