java.lang.IllegalStateException: Committed。大多出現在sendRedirect或forward時發生,通常解法是:
request.setAttribute("result", finaldata);
request.getRequestDispatcher("calculation.jsp").forward(request, response); // 因為request的attribute屬性要隨著forward跳轉。
而我在Struts 1開發時也有這個問題,當我google到上述解法時,才恍然原來我是用Ajax去call Struts的Action並以JSON回傳,也就是我在Action的內容如下:
JSONArray json = JSONArray.fromObject(list); |
因為使用response的getWriter來print和Struts1的findForward等於做了重複的output,out.print可以正常顯示結果後執行findForward就出現上述異常了。
全站熱搜