报错看下Failed to load resource: the server responded with a status of 500 (Internal Server Error)?
我是一个Random验证码的action,写在前台登录窗口那里的,以前还好好的,最近就这样了。
< div class="control-group">
< label class="control-label" for="inputPassword">验证码
< div class="controls">
< input type="password" name="checklist" id="inputPassword" placeholder="Password">
< img src="rand.action" onclick="changeValidateCode(this)" />
< /div>
< /div>
这是前台代码
function changeValidateCode(obj) {
var currentTime= new Date().getTime();
obj.src = "rand.action?d=" + currentTime;
}
调用的js函数
然后action类
public class RandomPictureAction extends ActionSupport
{
public RandomPictureAction()
{
}
public String execute()
throws Exception
{
int width = 85;
int height = 20;
BufferedImage image = new BufferedImage(width, height, 1);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman", 0, 18));
g.setColor(getRandColor(160, 200));
for(int i = 0; i < 155; i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
String sRand = "";
for(int i = 0; i < 6; i++)
{
String rand = String.valueOf(random.nextInt(10));
sRand = (new StringBuilder(String.valueOf(sRand))).append(rand).toString();
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 13 * i + 6, 16);
}
ActionContext.getContext().getSession().put("rand", sRand);
g.dispose();
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageOutputStream imageOut = ImageIO.createImageOutputStream(output);
ImageIO.write(image, "JPEG", imageOut);
imageOut.close();
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
setInputStream(input);
return "success";
}
private Color getRandColor(int a, int b)
{
Random random = new Random();
if(a > 255)
a = 255;
if(b > 255)
b = 255;
int R = a + random.nextInt(b - a);
int G = a + random.nextInt(b - a);
int B = a + random.nextInt(b - a);
return new Color(R, G, B);
}
public void setInputStream(ByteArrayInputStream inputStream)
{
this.inputStream = inputStream;
}
public ByteArrayInputStream getInputStream()
{
return inputStream;
}
private ByteArrayInputStream inputStream;
}
配置action的struts.xml
< ation name="rand" class="action.RandomPictureAction">
< result type="stream">
< param name="contentType">image/jpeg
< param name="inputName">inputStream
< /result>
< /action>
然后就出现了上面的错误,前台界面显示不出验证码图片,