我通过从动态图像 url 传递参数来调用 struts2 动作
<img src="<s:url action='ImageAction?imageId=logo.jpg' />"/>
有了这个,我的动作可以正确调用,但参数imageId=logo.jpg
没有传递给我的动作类。
但是,如果我从浏览器 url 手动传递参数,那么参数会正确显示到我的 java 页面中,例如。http://localhost:8080/mypoject/jspHomepage/bookstransaction/secure/ImageAction?imageId=logo.jpg
这可能是什么原因?请帮我。
struts.xml
`
`<package name="Image" extends="struts-default,json-default">
<result-types>
<result-type name="imageResult"
class="v.esoft.actions.changetheme.CustomImageBytesResult" />
</result-types>
<action name="updatethemeimageform" class="v.esoft.actions.changetheme.ThemedetailsEditAction" method="updateThemesImage">
<result name="success" type="json"/>
<result name="input" type="json"/>
</action>
<action name="Display" class="v.esoft.actions.changetheme.DisplayAction">
<result name="success" type="json"/>
</action>
<action name="ImageAction" class="v.esoft.actions.changetheme.ImageAction">
<result name="success" type="imageResult">
</result>
</action>
</package>`
ImageAction.java
public class ImageAction extends ActionSupport implements ServletRequestAware {
byte[] imageInByte = null;
String imageId;
private HttpServletRequest servletRequest;
public String getImageId() {
return imageId;
}
public void setImageId(String imageId) {
this.imageId = imageId;
}
public ImageAction() {
System.out.println("ImageAction");
}
public String execute() {
return SUCCESS;
}
public byte[] getCustomImageInBytes() {
System.out.println("imageId" + imageId);
}
}