jsp页面的值:
$.ajax({
url:"receive.action",
daty:"post",
success: function(data){
alert(data);
$("#receive").val(data);
}
});
后台代码:
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter pw = response.getWriter();
response.setCharacterEncoding("gbk");
response.setContentType("text/html");
pw.write("你好");
pw.flush();
怎样修改 让页面接收字符串呢?
daty:"post",
应该是type="post"
pw.flush();=>pw.End();
还有utf-8的也可以表示汉字的
网页的标准编码就是UTF-8
response.setCharacterEncoding("gbk");改为response.setCharacterEncoding("UTF-8");
页面的代码:
$.ajax({
url:"receive.action",
type:"post",
dataType:"text",
success: function(data){
alert(data);
$("#receive").val(data);
}
});
后台代码:
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
pw.write("你好");
pw.close();
@longyin: 怎么还是不行啊
@longyin:
此处看看呢
建议看下 页面里的编码和ajax输出的编码是否一致
<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="utf-8"%> 不知道怎么还是不对
@longyin: 火狐下看看 页面和输出的编码是否 正确