做毕设出现一个java.lang.StackOverflowError异常。弄了半天,又是问高手,又是查资料的。最后发现,解决问题啦!特记录下来!
StackOverflowError是由于当前线程的栈满了 ,也就是函数调用层级过多导致。
比如死递归。
以上是网上查阅的资料。
看懂后,我发现我的项目用的servlet技术,讲doGet()方法添加方法this.doPost()得到解决。
思考:应该是我在实现分页的时候,在点击上一页,下一页时,调用servlet函数后再调回本页面是,出现循环。
result.jsp
<% int pageNow = Integer.parseInt((String) request .getAttribute("pageNow")); if (pageNow != 1) { out.println("<a href=Db_sel_Servlet?dbversion=Mysql&pageNow=" + (pageNow - 1) + ">上一页</a>"); } String s_pageCount = (String) request.getAttribute("pageCount"); int pageCount = Integer.parseInt(s_pageCount); for (int i = 1; i <= pageCount; i++) { out.println("<a href=Db_sel_Servlet?dbversion=Mysql&pageNow=" + i + ">[" + i + "]</a>"); } if (pageNow != pageCount) { out.println("<a href=Db_sel_Servlet?dbversion=Mysql&pageNow=" + (pageNow + 1) + ">下一页</a>"); } %>
public class Db_sel_Servlet extends HttpServlet { public String flag; protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doPost(req, resp); } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { String s_pageNow=req.getParameter("pageNow"); int pageNow=Integer.parseInt(s_pageNow); System.out.println("DB_sel_Servlet.java---->>>pageNow:"+pageNow); flag = req.getParameter("dbversion"); System.out.println("DB_sel_Servlet---->>" + flag); File file = new File("D:\\workspace\\version"); FileUtil.WriteFile(file, flag); UserDaoImpl userDaoImpl = new UserDaoImpl(); List<User> user_list = userDaoImpl.getUsersByPage(pageNow); int pageCount=userDaoImpl.getPageCount(); System.out.println("DB_sel_Servlet.java---->>>pageCount:"+pageCount); req.setAttribute("result", user_list); req.setAttribute("pageCount", pageCount+""); req.setAttribute("pageNow",pageNow+""); System.out.println(user_list); // 清空文件内的内容 FileUtil.EmptyFile(file); // 跳转到用户管理页面 req.getRequestDispatcher("result.jsp").forward(req, resp); } catch (Exception e) { e.printStackTrace(); } }