ajax乱码问题,100分相送。
一:servlet.java文件内容如下:
package com.lz;
import
java.io.IOException;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SelectUser extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ // 生成一个随机数
//response.setHeader( "Content-Type ", "text/html;charset=utf-8 ");
StringBuffer sb = new StringBuffer();
sb.append( " <?xml version= '1.0 ' encoding= 'utf-8 '?> ");
// 将生成的随机数通过response对象写到客户端去,客户端接收将值写页面的recieveValue中。在这里就可以查询数据库,将查询的结果返回
String a = "select * from user where name= ' "+request.getParameter( "name ")+ " ' and mobile= ' "+request.getParameter( "mobile ")+ " ' " ;
System.out.println(a);
try {
DB db=new DB();
java.sql.ResultSet rs = db.executeQuery(a);
sb.append( " <message> ");
while(rs.next()){
sb.append( " <info> "+rs.getString( "address ")+ " </info> ");
sb.append( " <info> "+rs.getString( "postalcode ")+ " </info> ");
sb.append( " <info> "+rs.getString( "phone ")+ " </info> ");
sb.append( " <info> "+rs.getString( "phone1 ")+ " </info> ");
sb.append( " <info> "+rs.getString( "phone2 ")+ " </info> ");
sb.append( " <info> "+rs.getString( "email ")+ " </info> ");
}
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " <info> "+ " "+ " </info> ");
sb.append( " </message> ");
db.close();
} catch (Exception e) {
// TODO Auto-generated ca