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图片没有显示出来,