当前位置:Gxlcms >
数据库问题 >
ajax交互servlet返回数据和jdbc模糊查询-中文-已经设置了UTF-8和解决了乱码
ajax交互servlet返回数据和jdbc模糊查询-中文-已经设置了UTF-8和解决了乱码
时间:2021-07-01 10:21:17
帮助过:42人阅读
ajax
<script type="text/javascript">
function findsc(){
$(‘#metable‘
).empty();
$.ajax({
url: "find"
,
type: "get"
,
data:{
key:$(‘#keywords‘
).val()
},
success:function(data){
alert(data);
$(‘#metable‘
).append(data);
}
});
}
</script>
//servlet关键
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8"
);
response. setCharacterEncoding("UTF-8"
);
response.getWriter().append("Served at: "
).append(request.getContextPath());
MyServiceDao myServiceDao=
new MyServiceDao();
List<Sc>
temp;
PrintWriter outme=
response.getWriter();
outme.print("<tr><td style=‘background:#FFF68F;‘>学号</td><td style=‘background:#FFF68F;‘>姓名</td><td style=‘background:#FFF68F;‘>语文</td><td style=‘background:#FFF68F;‘>数学</td><td style=‘background:#FFF68F;‘>英语</td><tr>"
);
try {
temp=myServiceDao.getScByName(request.getParameter("key"
));
for(Sc sc : temp){
outme.print(
"<tr><td style=‘background:#CAFF70;‘>"+
sc.getId()
+"</td><td style=‘background:#CAFF70;‘>"+
sc.getName()
+"</td><td style=‘background:#CAFF70;‘>"+
sc.getYuwen()
+"</td><td style=‘background:#CAFF70;‘>"+
sc.getShuxue()
+"</td><td style=‘background:#CAFF70;‘>"+
sc.getYingyu()
+"</td><tr>"
);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
outme.close();
}
ajax交互servlet返回数据和jdbc模糊查询-中文-已经设置了UTF-8和解决了乱码
标签:iso 结果 get clip 表单 ... 数据 传递数据 工程