各位,我在网上找不到这个信息。我有一个操作,并且正在生成一个文本文件,但是始终以“generatePDF.action”文件的形式向客户端显示。我希望它显示为receipt.txt 文件。
这是我的注释:
@Action(value = "/generateTXT",
results = {
@Result(name = "ok", type = "stream",
params = {"inputName", "inputStream",
"contentType", "application/octet-stream",
"contentDispostion", "attachment;filename=receipt.txt"})
})
如果您使用的是约定插件,那么让我们使用以下代码作为参考,在“/YourApplicationContext/stream/stream-test”下运行,然后解析为“/YourApplicationContext/stream/document.txt”:
package struts2.stream;
import com.opensymphony.xwork2.ActionSupport;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import org.apache.struts2.convention.annotation.Result;
@Result(name = ActionSupport.SUCCESS, type = "stream", params =
{
"contentType",
"text/hmtl",
"inputName",
"inputStream",
"contentDisposition",
"filename=document.txt"
})
public class StreamTestAction extends ActionSupport{
public InputStream inputStream;
@Override
public String execute(){
inputStream = new StringBufferInputStream("Hello World! This is a text string response from a Struts 2 Action.");
return SUCCESS;
}
}
请注意“contentDisposition”,其值已设置为“filename='document.txt'”,更改“document.txt”即可获得您想要的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)