伙计们,我无法在网上清楚地找到这些信息.我有一个动作,我正在生成一个文本文件,但总是作为"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"})
})
Run Code Online (Sandbox Code Playgroud)
如果您正在使用约定插件,那么让我们使用以下代码进行"/ 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;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意"contentDisposition"并将其值设置为"filename ='document.txt'"更改'document.txt'可以获得您想要的内容.
| 归档时间: |
|
| 查看次数: |
3766 次 |
| 最近记录: |