我可以在 struts.xml 配置中定义它。
<action name="getImage" class="my.action.GetImageAction">
<result name="success" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">imageStream</param>
<param name="bufferSize">1024</param>
</result>
</action>
我现在正尝试通过在类上使用 namesapce 和 result path 进行注释来定义它,但我不知道该怎么做。请帮助:)
我试过了
@Namespace("/my/namespace")
@ResultPath("/")
@Result(name = "success", type = "imageResult")
public class GetImageAction extends ActionSupport {
.....
@Override
@Action("/getImage")
public String execute() throws Exception {
.....
我得到了一个错误
HTTP Status 404 - No result defined for action
最佳答案
正如错误所说,结果必须在操作中定义。 定义看起来像这样
@Action(value = "getImage", results = { @Result(
name = "success",
type = "stream",
params = {"contentType", "application/pdf" }) })
在示例中,您也看到了类型以及如何定义 contentType。
流将由“getFileInputStream”方法返回:
public InputStream getFileInputStream() {
return fileInputStream;
}
“getContentDisposition”方法必须在 Action 类中可用
public String getContentDisposition() {
return "attachment; filename=" + getFilename() + ".pdf";
}
关于java - 如何使用图像结果定义 Action 的注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390380/