server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
index.jsp
<%@ page language="java" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>旅游景点</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="js/Scripts/swfobject_modified.js" type="text/javascript"></script>
<script src="js/cascade.js" type="text/javascript"></script>
<!-- 搜索框 -->
<script type="text/javascript">
function searchName1() {
var name = document.getElementById("name").value;
if (name == null || name == 0 || name == "输入景点") {
alert("请输入景点名称!");
return false;
} else {
document.getElementById("form1").action="wt.do?fy=search&name=" + name;
document.getElementById("form1").submit();
}
}
function aothSubmit() {
if (event.keyCode == 13) {
var name = document.getElementById("name").value;
if (name == null || name == 0 || name == "输入景点") {
alert("请输入景点名称!");
return false;
} else {
document.getElementById("form1").action="wt.do?fy=search&name=" + name;
document.getElementById("form1").submit();
}
}
}
</script>
<script type="text/javascript">
//得到焦点时出发事件
function OnFocusFun(element, elementvalue) {
if (element.value == elementvalue) {
element.value = "";
element.style.color = "#000";
}
}
//离开输入框时触发事件
function OnBlurFun(element, elementvalue) {
if (element.value == "" || element.value.replace(/\s/g, "") == "") {
element.value = elementvalue;
element.style.color = "#999";
}
}
</script>
</head>
<body>
<div id="wrap">
<!--搜索框-->
<div id="search">
<div id="search_box">
<form id="form1" method="post" name="form1">
<input type="text" value="输入景点" id="name" class="swap_value"
name="name" onfocus="OnFocusFun(this,'输入景点')" style="color: #999"
onblur="OnBlurFun(this,'输入景点')" onkeypress="aothSubmit()"/>
<input type="button" class="button5" name="search" onclick="searchName1()" value="查一下">
</form>
</div>
</div>
</body>
</html>
fyAction.class
// 搜索框
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String name = request.getParameter("name");
String ScenicName = new String(name.getBytes("ISO-8859-1"),"gbk");
System.out.println("ScenicName= "+ScenicName);
FyDao fd = new FyDao();
Scenic scenic = new Scenic();
scenic = fd.search(ScenicName);
request.setAttribute("scenic", scenic);
if (scenic != null) {
String id = scenic.getId();
List<SightSpot> sightSpots = fd.listSightSpot(id);
request.setAttribute("sightSpots", sightSpots);
return mapping.findForward("detail");
} else {
return mapping.findForward("error");
}
}
}
16 个解决方案
#1
什么乱码?没说清楚啊
#2
是不是服务器的编码和你开发环境不一样?
#3
是本地显示正常,服务器乱码。服务器上的tomcat 也是
server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
#4
服务器是linux的吗??
#5
Server 2003的服务器
#6
你贴出来的tomcat的service.xml的部分有加过编码“utf—8”的设置么
#7
没有,本地和服务器都没有编码设置
#8
那就在tomcat的server.xml中,配置Connector项,也就是你刚才贴上的那段,加上属性URIEncoding="GBK"(编码形式和你jsp的一样就行了,不过我一般把所有的设置成utf-8)
#9
不过我很纠结,是这样的。我在部署到服务器的时候还需要加上编码,要是不加编码服务器就显示乱码,代码如下
ScenicDAO.class
// 根据景区id获取景点
public List<SightSpot> listSightSpot(String scenicId) throws Exception {
conn = ConnUtil.conn();
sql = ConnUtil.sql();
stmt = ConnUtil.stmt();
rs1 = sql.executeQuery("Select * from WTsightSpot where SId="
+ scenicId);
List<SightSpot> SightSpots = new ArrayList<SightSpot>();
while (rs1.next()) {
SightSpot s = new SightSpot();
s.setId(rs1.getString("id"));
s.setJdName(new String(rs1.getBytes("JdName"), "gbk"));
s.setImg(new String(rs1.getBytes("Img"), "gbk"));
s.setMajorScenic(new String(rs1.getBytes("majorScenic"), "gbk"));
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
s.setOpenTime(rs1.getString("OpenTime"));
SightSpots.add(s);
}
return SightSpots;
}
ScenicDAO.class
// 根据景区id获取景点
public List<SightSpot> listSightSpot(String scenicId) throws Exception {
conn = ConnUtil.conn();
sql = ConnUtil.sql();
stmt = ConnUtil.stmt();
rs1 = sql.executeQuery("Select * from WTsightSpot where SId="
+ scenicId);
List<SightSpot> SightSpots = new ArrayList<SightSpot>();
while (rs1.next()) {
SightSpot s = new SightSpot();
s.setId(rs1.getString("id"));
s.setJdName(new String(rs1.getBytes("JdName"), "gbk"));
s.setImg(new String(rs1.getBytes("Img"), "gbk"));
s.setMajorScenic(new String(rs1.getBytes("majorScenic"), "gbk"));
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
s.setOpenTime(rs1.getString("OpenTime"));
SightSpots.add(s);
}
return SightSpots;
}
#10
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
这样转了跟没转一个样。。。。。。tomcat服务器一般都要改的编码格式,你用框架什么的话 可以使用过滤器设置一下
这样转了跟没转一个样。。。。。。tomcat服务器一般都要改的编码格式,你用框架什么的话 可以使用过滤器设置一下
#11
不是的!~我在没有s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
这样转码的时候,服务器上显示乱码,转码后好了,我有写了过滤器,
public void doFilter(ServletRequest httpServletRequest, ServletResponse httpServletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) httpServletRequest;
HttpServletResponse response = (HttpServletResponse) httpServletResponse;
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
chain.doFilter(request, response);
}
可是没有用!~蛋疼啊
这样转码的时候,服务器上显示乱码,转码后好了,我有写了过滤器,
public void doFilter(ServletRequest httpServletRequest, ServletResponse httpServletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) httpServletRequest;
HttpServletResponse response = (HttpServletResponse) httpServletResponse;
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
chain.doFilter(request, response);
}
可是没有用!~蛋疼啊
#12
是不是英文版的,需要在区域语言中修改为中文;
http://os.51cto.com/art/200512/15850.htm
在查看你的服务器配置,是不是apache tomcat
如果是安装版的需要添加支持字符集操作。
#13
写一个过滤器。把请求转成gbk
#14
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
第二种方法
s.setImg(new String( String.valueOf(rs.getByte("majorScenic")).getBytes("iso-8859-1"),"GBK"));
第三种方法
public void setServletRequest(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
Logger.getLogger("hnww_error.log").error(e.getMessage());
}
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
response.setCharacterEncoding("utf-8");
}
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
第二种方法
s.setImg(new String( String.valueOf(rs.getByte("majorScenic")).getBytes("iso-8859-1"),"GBK"));
第三种方法
public void setServletRequest(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
Logger.getLogger("hnww_error.log").error(e.getMessage());
}
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
response.setCharacterEncoding("utf-8");
}
#15
告诉服务器的JVM,使用和开发环境一样的编码方式启动,就可以了。
开发环境和运行环境保持同样的编码,就不会有这样的问题。
改代码的方式都不是好办法。
开发环境和运行环境保持同样的编码,就不会有这样的问题。
改代码的方式都不是好办法。
#16
还是不行啊!试过很多办法!求解
#1
什么乱码?没说清楚啊
#2
是不是服务器的编码和你开发环境不一样?
#3
是本地显示正常,服务器乱码。服务器上的tomcat 也是
server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
#4
服务器是linux的吗??
#5
Server 2003的服务器
#6
你贴出来的tomcat的service.xml的部分有加过编码“utf—8”的设置么
#7
没有,本地和服务器都没有编码设置
#8
那就在tomcat的server.xml中,配置Connector项,也就是你刚才贴上的那段,加上属性URIEncoding="GBK"(编码形式和你jsp的一样就行了,不过我一般把所有的设置成utf-8)
#9
不过我很纠结,是这样的。我在部署到服务器的时候还需要加上编码,要是不加编码服务器就显示乱码,代码如下
ScenicDAO.class
// 根据景区id获取景点
public List<SightSpot> listSightSpot(String scenicId) throws Exception {
conn = ConnUtil.conn();
sql = ConnUtil.sql();
stmt = ConnUtil.stmt();
rs1 = sql.executeQuery("Select * from WTsightSpot where SId="
+ scenicId);
List<SightSpot> SightSpots = new ArrayList<SightSpot>();
while (rs1.next()) {
SightSpot s = new SightSpot();
s.setId(rs1.getString("id"));
s.setJdName(new String(rs1.getBytes("JdName"), "gbk"));
s.setImg(new String(rs1.getBytes("Img"), "gbk"));
s.setMajorScenic(new String(rs1.getBytes("majorScenic"), "gbk"));
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
s.setOpenTime(rs1.getString("OpenTime"));
SightSpots.add(s);
}
return SightSpots;
}
ScenicDAO.class
// 根据景区id获取景点
public List<SightSpot> listSightSpot(String scenicId) throws Exception {
conn = ConnUtil.conn();
sql = ConnUtil.sql();
stmt = ConnUtil.stmt();
rs1 = sql.executeQuery("Select * from WTsightSpot where SId="
+ scenicId);
List<SightSpot> SightSpots = new ArrayList<SightSpot>();
while (rs1.next()) {
SightSpot s = new SightSpot();
s.setId(rs1.getString("id"));
s.setJdName(new String(rs1.getBytes("JdName"), "gbk"));
s.setImg(new String(rs1.getBytes("Img"), "gbk"));
s.setMajorScenic(new String(rs1.getBytes("majorScenic"), "gbk"));
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
s.setOpenTime(rs1.getString("OpenTime"));
SightSpots.add(s);
}
return SightSpots;
}
#10
s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
这样转了跟没转一个样。。。。。。tomcat服务器一般都要改的编码格式,你用框架什么的话 可以使用过滤器设置一下
这样转了跟没转一个样。。。。。。tomcat服务器一般都要改的编码格式,你用框架什么的话 可以使用过滤器设置一下
#11
不是的!~我在没有s.setTicketPrice(new String(rs1.getBytes("TicketPrice"), "gbk"));
这样转码的时候,服务器上显示乱码,转码后好了,我有写了过滤器,
public void doFilter(ServletRequest httpServletRequest, ServletResponse httpServletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) httpServletRequest;
HttpServletResponse response = (HttpServletResponse) httpServletResponse;
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
chain.doFilter(request, response);
}
可是没有用!~蛋疼啊
这样转码的时候,服务器上显示乱码,转码后好了,我有写了过滤器,
public void doFilter(ServletRequest httpServletRequest, ServletResponse httpServletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) httpServletRequest;
HttpServletResponse response = (HttpServletResponse) httpServletResponse;
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
chain.doFilter(request, response);
}
可是没有用!~蛋疼啊
#12
是不是英文版的,需要在区域语言中修改为中文;
http://os.51cto.com/art/200512/15850.htm
在查看你的服务器配置,是不是apache tomcat
如果是安装版的需要添加支持字符集操作。
#13
写一个过滤器。把请求转成gbk
#14
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
第二种方法
s.setImg(new String( String.valueOf(rs.getByte("majorScenic")).getBytes("iso-8859-1"),"GBK"));
第三种方法
public void setServletRequest(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
Logger.getLogger("hnww_error.log").error(e.getMessage());
}
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
response.setCharacterEncoding("utf-8");
}
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
第二种方法
s.setImg(new String( String.valueOf(rs.getByte("majorScenic")).getBytes("iso-8859-1"),"GBK"));
第三种方法
public void setServletRequest(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
Logger.getLogger("hnww_error.log").error(e.getMessage());
}
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
response.setCharacterEncoding("utf-8");
}
#15
告诉服务器的JVM,使用和开发环境一样的编码方式启动,就可以了。
开发环境和运行环境保持同样的编码,就不会有这样的问题。
改代码的方式都不是好办法。
开发环境和运行环境保持同样的编码,就不会有这样的问题。
改代码的方式都不是好办法。
#16
还是不行啊!试过很多办法!求解