%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <% String body = request.getParameter("body"); String filename = request.getParameter("filename"); if (filename == null) filename = "export.txt"; if (body != null) { response.setContentType("text/plain"); response.setHeader("Content-Disposition","attachment; filename="+filename); out.print(body); return; } %>
Usage: body - body of document filename - filename of document