SEVERE: Servlet.service() for servlet default threw exception java.lang.StackOve

longzl123 2014-12-11 08:57:51
http://www.3c60.com/others/1.log

请问这个是什么原因引起的
...全文
106 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
longzl123 2014-12-11
  • 打赏
  • 举报
回复

有可能是验证码的问题   
<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*,java.text.*,com.cloudsoar3c.tools.*" pageEncoding="utf-8"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.awt.geom.Arc2D"%>
<%!String[] fonts = { "宋体", "楷体","黑体","Arial","Times New Roman"};// 字体
	//String[] fonts2 = {"华文彩云"};// 字体
	//int[] styles = { Font.PLAIN, Font.BOLD, Font.ITALIC,
	//		Font.BOLD + Font.ITALIC };// 样式
	int[] styles2 = { Font.PLAIN, Font.ITALIC, Font.ITALIC, Font.ITALIC };// 样式
	//int[] sizes = { 14, 15, 16, 17, 18, 19, 20 };// 字体大小
	//int[] sizes2 = { 18, 19, 20, 18, 19, 20, 20 };// 字体大小

	Color getRandColor(int fc, int bc) {//给定范围获得随机颜色
		Random random = new Random();
		if (fc > 255)
			fc = 255;
		if (bc > 255)
			bc = 255;
		int r = fc + random.nextInt(bc - fc);
		int g = fc + random.nextInt(bc - fc);
		int b = fc + random.nextInt(bc - fc);
		return new Color(r, g, b);
	}

	%>
<%
	try {
		//设置页面不缓存
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);

		// 在内存中创建图象
		int width = 3000, height = 500;
		BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
		BufferedImage image_error = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);

		// 获取图形上下文
		Graphics gr = image.getGraphics();

		Graphics2D g = (Graphics2D) gr;
		g.setStroke(new BasicStroke(3));//设置线条的粗细
		//生成随机类
		Random random = new Random();
		// 设定背景色
		g.setColor(getRandColor(200, 250));
		g.fillRect(0, 0, width, height);
		g.drawRect(0, 0, width - 1, height - 1);
		String sRand = Code.getCode(session);//rand
        
		g.setColor(getRandColor(10, 100));
		g.setFont(new Font(fonts[0], styles2[0], 550));
		g.drawString(sRand, 5, 450);
		// 图象生效
		g.dispose();
		ImageIO.write(image, "JPEG", response.getOutputStream());
        out.clear();
        out=pageContext.pushBody();

	} catch (Exception e) {
		e.printStackTrace();
	}
%>

public static String getCode(HttpSession session) {

	boolean hasBrackets = false;
	float num1, num2, num3, result = -1;
	char op1, op2;
	text = new String();
	boolean running = true;
	try {
	    do {
		num1 = getNum(1, 5);
		num2 = getNum(1, 5);
		num3 = getNum(1, 5);
		op1 = getOp();
		op2 = getOp();
		text = new String();
		hasBrackets = false;
		if (op1 == op2) {
		    continue;
		}
		hasBrackets = hasBrackets();
		// 添加括号
		if (hasBrackets) {
		    result = getBracketsStr(num1, num2, num3, op1, op2, position);
		    if (result > 0) {
			running = false;
		    }
		} else {
		    result = getStr(num1, num2, num3, op1, op2);
		    if (result > 0) {
			running = false;
		    }
		}
	    } while (running);
	    byte[] encryptResult = Encrypt.encrypt((((int) result) + "").toLowerCase());
	    String encryptResultStr = Encrypt.parseByte2HexStr(encryptResult);
	    Util.log("Code.java    code = " + ((int) result) + "||encryptResultStr = " + encryptResultStr);
	    session.setAttribute("rand", encryptResultStr);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return text;

    }
super_Leon 2014-12-11
  • 打赏
  • 举报
回复
HttpServletRequestWrapper.getSession中调用了ApplicationHttpRequest.getSession,又在ApplicationHttpRequest.getSession中调用了HttpServletRequestWrapper.getSession,所以产生了死循环了! 你看下你的项目里哪里用了循环 导致内存溢出了

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧