NeQrhk 2017-05-30 05:12 采纳率: 30.6%
浏览 498

我是一个Random验证码的action,写在前台登录窗口那里的,以前还好好的,最近就这样了。

报错看下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>
然后就出现了上面的错误,前台界面显示不出验证码图片,

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料