NeQrhk 2017-06-02 10:17 采纳率: 30.6%
浏览 848

struts2 错误, 验证码问题,报错,谁帮我看下,img图片显示不了验证码?


java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the tag specified for this action.
org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:237)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)


我的form表单
< input type="password" name="checklist" id="inputPassword" placeholder="Password">
< img src="rand.action" onclick="changeValidateCode(this)" />

这是前台代码
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>

结果img图片没有显示出来,

  • 写回答

1条回答 默认 最新

  • NeQrhk 2017-06-02 10:19
    关注

    应该是inputStream没有的问题,不过不知道怎么判断到底是不是这也问题,这里好像不是路径的问题吧

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型