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

Posted rocky-fang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter相关的知识,希望对你有一定的参考价值。

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类型的值,错误解决。

以上是关于struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter的主要内容,如果未能解决你的问题,请参考以下文章

Struts2标签库

Struts2框架使用之struts2的验证框架

Struts2学习笔记

Struts2学习笔记

struts2系列:struts2参数传递错误struts2的输入错误验证

Struts2学习笔记二:Struts2重定向和转发配置Struts2获取表单参数域对象