XPages 通过 SSJS 创建 .txt 文件
XPages to create .txt File via SSJS
我需要用 SSJS 创建一个文本文件。我从文档中获取数据,然后将所有数据写入文本文件。我尝试了一些在互联网上搜索的解决方案,但无法获得所需的结果。
此致
任何建议表示赞赏
Cumhur Ata
更新:
writer.endDocument();
facesContext.responseComplete();
writer.close();
更新 2:
<xp:button value="Create TXT File" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
response.setContentType("text/plain; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Content-Disposition", "attachment; filename=\"file.txt\"" );
var strEntr = "\n";
var str1 = "TXTV2[] \n";
str1 += "NUMBER|CLIENT_ID|START_DATE|END_DATE|\n";
str1 += "UNITS|DESCRIPTION|CLASSIFICATION|"+strEntr;
str1 += "[]";
response.getOutputStream().write(str1.getBytes());
facesContext.responseComplete(); }]]></xp:this.action>
</xp:eventHandler></xp:button>
您应该在 SSJS 中初始化 Java 代码。
importPackage(Java class) // whole Java class name with package !!!not string
var tmp = new ImportedClassName()
tmp.run() // run all logic
希望能帮到你。最好的问候。
此示例会将字符串的内容下载为 txt 文件。
希望对您有所帮助。
var textBuffer = "some text here";
var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Content-Disposition", "attachment; filename=\"file.txt\"" );
response.getOutputStream().write(textBuffer.getBytes());
facesContext.responseComplete();
我需要用 SSJS 创建一个文本文件。我从文档中获取数据,然后将所有数据写入文本文件。我尝试了一些在互联网上搜索的解决方案,但无法获得所需的结果。
此致
任何建议表示赞赏
Cumhur Ata
更新:
writer.endDocument();
facesContext.responseComplete();
writer.close();
更新 2:
<xp:button value="Create TXT File" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
response.setContentType("text/plain; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Content-Disposition", "attachment; filename=\"file.txt\"" );
var strEntr = "\n";
var str1 = "TXTV2[] \n";
str1 += "NUMBER|CLIENT_ID|START_DATE|END_DATE|\n";
str1 += "UNITS|DESCRIPTION|CLASSIFICATION|"+strEntr;
str1 += "[]";
response.getOutputStream().write(str1.getBytes());
facesContext.responseComplete(); }]]></xp:this.action>
</xp:eventHandler></xp:button>
您应该在 SSJS 中初始化 Java 代码。
importPackage(Java class) // whole Java class name with package !!!not string
var tmp = new ImportedClassName()
tmp.run() // run all logic
希望能帮到你。最好的问候。
此示例会将字符串的内容下载为 txt 文件。
希望对您有所帮助。
var textBuffer = "some text here";
var con = facesContext.getExternalContext();
var response:com.ibm.xsp.webapp.XspHttpServletResponse = con.getResponse();
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Content-Disposition", "attachment; filename=\"file.txt\"" );
response.getOutputStream().write(textBuffer.getBytes());
facesContext.responseComplete();