<a href="list.action?code=信息">信息</a>点击链接我到java后台接受“信息”字符进行验证,但我测试时显示得到的是??????
查看网上我在java中添加了
code = new String(((String)request.getParameter("code")).getBytes("gb2312"),"utf-8");如果写成
code = new String(((String)request.getParameter("code")).getBytes("utf-8"),"gb2312");
则报乱码错误我该怎样解决啊????//jsp上的配置信息
<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<jsp:useBean id="db2" scope="page" class="db2.Db2"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
查看网上我在java中添加了
code = new String(((String)request.getParameter("code")).getBytes("gb2312"),"utf-8");如果写成
code = new String(((String)request.getParameter("code")).getBytes("utf-8"),"gb2312");
则报乱码错误我该怎样解决啊????//jsp上的配置信息
<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<jsp:useBean id="db2" scope="page" class="db2.Db2"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
code = new String(((String)request.getParameter("code")).getBytes("gb2312"),"utf-8");
这种方式好像会编译两次 所以你设的编码方式没起作用 因为第二次编译的时候并没有设置编码方式期待 ...
code = new String(((String)request.getParameter("code")).getBytes("gb2312"),"utf-8"); 如果写成
code = new String(((String)request.getParameter("code")).getBytes("utf-8"),"gb2312");
则报乱码错误
一般 上面的出来 非???号乱码???????这种乱码 一般是这种问题
就是你在请求后 才变的乱码
是get 方法的
所有你要
request.setCharacterEncoding("utf-8");
在得到code 那个页面的
<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
也就是这里
写上这2行代码
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
%>
试试看
希望对你的有帮助哦
^_*
Xml代码
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="GBK"/>
注意,如果是中文最好用GBK,我使用UTF-8时有乱码。