程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter,struts2printwriter

struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter,struts2printwriter

編輯:JAVA綜合教程

struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter,struts2printwriter


1. 問題描述:

   頁面通過異步訪問action,    action的方法通過map封裝數據,struts的result的type設置為json,後台報錯

六月 25, 2016 6:54:33 下午 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/msf] threw exception [Filter execution threw an exception] with root cause
java.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的代碼

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. 問題排查及解決方案

   以上紅色部分,向map中添加了兩個對象,結果值棧(StackOverflow)溢出。

   去掉一個對象page,改為加入String類型的值,錯誤解決。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved