java.lang.IllegalStateException: getOutputStream() has already been called for this response
这是什么错误?源代码:生成验证码<%intiWidth=130,iHeight=20;BufferedImageimage=newBufferedImage(iWidth...
这是什么错误?源代码:生成验证码
<%
int iWidth=130,iHeight=20;
BufferedImage image=new BufferedImage(iWidth,iHeight,BufferedImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,iWidth,iHeight);
g.setColor(Color.BLACK);
g.drawRect(0,0,iWidth-1,iHeight-1);
String rand=request.getParameter("Rand");
rand=rand.substring(0,rand.indexOf("."));
switch(rand.length())
{
case 1:rand="000"+rand;break;
case 2:rand="00"+rand;break;
case 3:rand="0"+rand;break;
case 4:rand=rand.substring(0,4);break;
}
session.setAttribute("YanZ",rand);
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,10,15);
Random random=new Random();
for(int iIndex=0;iIndex<88;iIndex++)
{
int x=random.nextInt(iWidth);
int y=random.nextInt(iHeight);
g.drawLine(x,y,x,y);
}
g.dispose();
ImageIO.write(image,"JPEG",response.getOutputStream());
%> 展开
<%
int iWidth=130,iHeight=20;
BufferedImage image=new BufferedImage(iWidth,iHeight,BufferedImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,iWidth,iHeight);
g.setColor(Color.BLACK);
g.drawRect(0,0,iWidth-1,iHeight-1);
String rand=request.getParameter("Rand");
rand=rand.substring(0,rand.indexOf("."));
switch(rand.length())
{
case 1:rand="000"+rand;break;
case 2:rand="00"+rand;break;
case 3:rand="0"+rand;break;
case 4:rand=rand.substring(0,4);break;
}
session.setAttribute("YanZ",rand);
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,10,15);
Random random=new Random();
for(int iIndex=0;iIndex<88;iIndex++)
{
int x=random.nextInt(iWidth);
int y=random.nextInt(iHeight);
g.drawLine(x,y,x,y);
}
g.dispose();
ImageIO.write(image,"JPEG",response.getOutputStream());
%> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询