我正在制作一个Web应用程序,可以在Java Servlet中使用休眠功能从数据库读取大数据。当我从数据库字段中读取大数据时,我将其成功地放入了String中,之后我想将其放入JSON中并将其传递给Javascript Ajax,但是对于JSON而言似乎数据太大。当我尝试将较小的JSON传递给Ajax时,它可以正常工作。怎么了?
这是我的Ajax:
$.post("servletispistabeleuseru", {"user":user}, function(data){
var tab=data.result;
console.log(tab);
});
这是我的Servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json");
String user=request.getParameter("user");
Configuration myConf = new Configuration();
myConf.configure("hib/hibernate.cfg.xml");
StandardServiceRegistry service = new StandardServiceRegistryBuilder().
applySettings(myConf.getProperties()).build();
SessionFactory myFactory = myConf.buildSessionFactory(service);
Session conn = myFactory.openSession();
Transaction t = conn.beginTransaction();
List<User>useri;
useri=conn.createQuery("SELECT u FROM User u WHERE useUsername='"+user+"'").list();
String result=useri.get(0).getUseKineski();
System.out.println(result);
t.commit();
conn.close();
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.print("{\"result\":\"" + result + "\"}");
}
}