java读取html文件内容显示在jsp中出现乱码?
url1是文件html文件位置。已知URLurl=null;InputStreaminput=null;Readerreader=null;BufferedReaderb...
url1是文件html文件位置。已知
URL url = null;
InputStream input = null;
Reader reader = null;
BufferedReader br = null;
StringBuffer contentBuffer = new StringBuffer();
try {
url = new URL(url1);
input = url.openStream();
reader = new InputStreamReader(input);
br = new BufferedReader(reader, 2048);
String inputLine = null;
while ((inputLine = br.readLine()) != null) {
contentBuffer.append(inputLine);
contentBuffer.append("\n");
}
input.close();
} catch (Exception e1) {
e1.printStackTrace();
}
request.setAttribute("msg", contentBuffer.toString());
return new ModelAndView("app/kindManage/articleResource/kuaizhao");
jsp设置
<%@ page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/commons/taglibs.jsp" %>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/js.jsp" %>
<%@page import="java.util.*"%>
<%@page import="com.gentlesoft.pubopinion.kindmanage.domain.*"%>
<html>
<head>
<title>快照</title>
</head>
<body >
<div align="left">
${msg}
</div>
</body>
</html> 展开
URL url = null;
InputStream input = null;
Reader reader = null;
BufferedReader br = null;
StringBuffer contentBuffer = new StringBuffer();
try {
url = new URL(url1);
input = url.openStream();
reader = new InputStreamReader(input);
br = new BufferedReader(reader, 2048);
String inputLine = null;
while ((inputLine = br.readLine()) != null) {
contentBuffer.append(inputLine);
contentBuffer.append("\n");
}
input.close();
} catch (Exception e1) {
e1.printStackTrace();
}
request.setAttribute("msg", contentBuffer.toString());
return new ModelAndView("app/kindManage/articleResource/kuaizhao");
jsp设置
<%@ page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/commons/taglibs.jsp" %>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/js.jsp" %>
<%@page import="java.util.*"%>
<%@page import="com.gentlesoft.pubopinion.kindmanage.domain.*"%>
<html>
<head>
<title>快照</title>
</head>
<body >
<div align="left">
${msg}
</div>
</body>
</html> 展开
展开全部
缺少个过虑器吧,加上这个试试:
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
追问
url = new URL(url1);
request.setCharacterEncoding("utf-8");
XXXXX
response.setCharacterEncoding("utf-8");
添加了之后 结果和原来一样,有的是乱码有的不是乱码。我原来的问题就是有些是乱码有些打开不是乱码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的java是用gbk编码的吧?
更多追问追答
追问
默认不设置是utf-8吧。改成gbk或者 UTF-8也是有乱码
追答
先在eclipse中打开这个html文件看是不是有乱码,有乱码的话说明html文件保存的时候没有按指定编码方式保存。然后确定jsp,Java代码,html文件编码是否一致,不一致的话需要转码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询