日期:2014-05-16 浏览次数:20563 次
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"utf-8"));
while(true){
String line = br.readLine();
if(line!=null){
sb.append(line+"\n");
}else{
break;
}
}
br.close();
//response.setCharacterEncoding("UTF-8"); //注意这里要在getWriter()之前。
PrintWriter out = response.getWriter();
//response.setContentType("text/html");
response.setContentType("text/html;charset=utf-8"); //写这里是没有任何作用的!!!!!!
System.out.println("sb:"+sb.toString());
//这么转化一下是否有必要?
String des = new String(sb.toString().getBytes("UTF-8"),"UTF-8");
System.out.println("des:"+des);
out.print(des);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
System.out.println("文件读取错误");
e.printStackTrace();
}
return null; request.setCharacterEncoding("uft-8")以后就不会乱码。URLDecoder.decode(content, "utf-8");解码。这样来解决乱码的问题。
function submitContent(){
var content = $("#txt").val();
var newcon = encodeURIComponent(content);
//post 提交方式
$.post("<%=basePath%>pkg_updatePage",
{ rootpath: allPath, content: newcon },
function(data){
var ll = confirm("are you sure?");
if(ll==true){
}else{
return;
}
});
} var allPath ;
function geteditData(name){
var path =rootPath+name;
allPath = path;
$.ajax({
async: false,
cache: false,
type:"POST", //post!
dataType: "text",
contentType:"application/x-www-form-urlencoded;charset=gbk",
url: "<%=basePath%>pkg_readPage?rootpath="+path, //?xxx=xxx
success : function(data){
//alert(typeof(data));
$("#txt").val(data);
},
error: function(){