整合Spring+Hibernate+Struts2的时候发现json数据一直无法传到页面,提示no-Session

 

执行了ajax,页面没有任何反应

怀疑json没有值,想查看json中的内容,使用了ObjectMapper:

ObjectMapper om=new ObjectMapper();
System.out.println(om.writeValueAsString(pb));//pb是我要返回的数据

页面始终无法得到json数据,在JQ代码中的回调函数alert()也没反应,在浏览器控制台发现了500错误:

 点击出现了一堆异常:

此处省略中间其他类似异常...

 

提示了懒加载的错误,所以我去设置了lazy="false",好像没啥用,可能是我配置错了地方

百度了一下如何关闭懒加载:

  hibernate中懒加载禁用的方式 - haha_66666的博客 - CSDN博客 https://blog.csdn.net/haha_66666/article/details/78586656

  使用了OpenSessionInViewFilter,使得Session延迟关闭.

<!-- 解决no-session问题过滤器 通过filter来让session在jsp页面完毕后再关闭session -->
<!-- 注意: 所有Filter的配置都需要放置在struts2入口过滤器配置之前 -->
<filter>
  <filter-name>openSessionInView</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>openSessionInView</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

经验总结:

  在MyEclipse中没有任何错误提示的情况下,去浏览器控制台看看

  在感觉出问题的地方之前打印控制台信息,确保程序是否进入本区域.

  在没有任何错误的提示的时候,很崩溃了,手动用try...catch将怀疑出问题的地方包围住!

posted @ 2019-05-12 01:14  Meiwah  阅读(150)  评论(0编辑  收藏  举报