Struts2 java. lang. StackOverflowError org. apache. struts2.json. JSONWriter, struts2printwriter
1. Problem description:
The page accesses action asynchronously. The action method encapsulates data through map. The struts result type is set to json, and an error is reported in the background.
June 25 6:54:33 org. apache. catalina. core. standardWrapperValve invokeSEVERE: Servlet. service () for servlet [default] in context with path [/msf] threw exception [Filter execution threw an exception] with root causejava. lang. stackOverflowError at sun. reflect. misc. reflectUtil. checkPackageAccess (ReflectUtil. java: 177) at sun. reflect. misc. reflectUtil. checkPackageAccess (ReflectUtil. java: 164) at sun. reflect. misc. reflectUtil. isPackageAccessible (ReflectUtil. java: 195) at java. beans. introspector. getBeanInfo (Introspector. java: 154) at org. apache. struts2.json. JSONWriter. bean (JSONWriter. java: 177) at org. apache. struts2.json. JSONWriter. process (JSONWriter. java: 160) at org. apache. struts2.json. JSONWriter. value (JSONWriter. java: 126) at org. apache. struts2.json. JSONWriter. add (JSONWriter. java: 352) at org. apache. struts2.json. JSONWriter. bean (JSONWriter. java: 215) at org. apache. struts2.json. JSONWriter. process (JSONWriter. java: 160)
2. action Code
package com.cdv.mediastar.action;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import com.cdv.mediastar.model.User;import com.cdv.mediastar.model.UserSessionlog;import com.cdv.mediastar.service.UserService;import com.cdv.mediastar.util.PageParameter;import com.opensymphony.xwork2.ActionSupport;@Scope("request")@Controller("logAction")public class LogAction extends ActionSupport { /** * */ private static final long serialVersionUID = -1455520770797186253L; Map<String, Object> dataMap = new HashMap<String, Object>(); public Map<String, Object> getDataMap() { return dataMap; } public void setDataMap(Map<String, Object> dataMap) { this.dataMap = dataMap; } @Resource private UserService userService; public String index(){ return "index"; } public String list(){ dataMap.clear(); PageParameter page = new PageParameter(); HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); User user = (User) session.getAttribute("user"); String userid = user.getUserid(); String appName = "Alkaid"; List<UserSessionlog> sessionlogList = userService.findlog(userid, appName, 0, page.getPageSize()); int totalCount = userService.countlog(userid, appName); int totalPage = totalCount%page.getPageSize()==0?totalCount/page.getPageSize():totalCount%page.getPageSize()+1; page.setTotalCount(totalCount); page.setTotalPage(totalPage); int startNum = 0, stopNum = 0; startNum = 1; if((startNum+page.getPageSize()-1)<=totalCount){ stopNum = startNum+page.getPageSize()-1; }else{ stopNum = totalCount; } dataMap.put("startNum", startNum); dataMap.put("stopNum", stopNum); dataMap.put("page", page); dataMap.put("sessionlogList", sessionlogList); return "success"; } }
3. troubleshooting and Solutions
The red part above adds two objects to the map, and the result value stack (StackOverflow) overflows.
Remove an object page and add a value of the String type. The error is fixed.