问题
I need to create a text file with SSJS. I get data from a document then i will write all data in a text file. I tried to some solution which i find searching on the internet but I could not get result I needed.
Regards
Any Suggestion is appreciated
Cumhur Ata
UPDATE:
writer.endDocument();
facesContext.responseComplete();
writer.close();
UPDATE 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>
回答1:
This example will download the content of a String as a txt-File.
Hope that helps.
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();
回答2:
You should initialize Java code in your SSJS.
importPackage(Java class) // whole Java class name with package !!!not string
var tmp = new ImportedClassName()
tmp.run() // run all logic
Hope I help. Best regards.
来源:https://stackoverflow.com/questions/35868865/xpages-to-create-txt-file-via-ssjs