How Can I put information in a outputstream from tapestry5?

How Can I put information in a outputstream from tapestry5 ?

I need a page when a user enters it open a dialog for save or open the file with the outputstream information.

I write the next code:

public class Index {

private RequestGlobals requestGlobals;

public void onActivate() {
    try {
        HttpServletResponse response = requestGlobals.getHTTPServletResponse();
        PrintWriter out = response.getWriter();
    } catch (IOException ex) {
        Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, ex);


I hope that the result is only "helloooooooo" but is ("helloooooooo" + my html raw page)

Asked by: Dexter893 | Posted: 21-01-2022

Answer 1

Your method should have a return type of StreamResponse. You return an implementation of the interface StreamResponse, which simply returns the data you want with the content type you want.

Look it up here:

more info here:

Answered by: Gianna863 | Posted: 22-02-2022

Answer 2

If you are dealing with large response streams, using StreamResponse can be somewhat inconvenient and inefficient (because you have to return an InputStream). Better would be to write response directly to OutputStream.

Fortunately, in Tapestry Wiki, there is a page for solving exactly this: Tapestry5: How To Create A Component Event Result Processor.

Answered by: Dainton887 | Posted: 22-02-2022

Similar questions

java - How to put the content of a ByteBuffer into an OutputStream?

I need to put the contents of a java.nio.ByteBuffer into an (wish I had a Channel instead but I don't) What's the best way to do this? I can't use the ByteBuffer's array() method since it can be a read-only buffer. I also may be interspersing writes to the OutputStream between using this ByteBuffer and having a regular array of ...

java - How can I implement an OutputStream that I can rewind?

After writing out some processed content to an output stream, I need to revisit the beginning of the stream and write out some content metadata. The data I'm writing is very large, as much as 4Gb, and may be written either directly to a file or to an in-memory buffer, depending on various environmental factors. How can I implement an OutputStream that allows me to write out headers after completing the writing of ...

file io - Switching Writers on an OutputStream in Java

I have one method that opens a file and passes off to another function to write some data to it. That second method wants to use PrintWriter to write its data. However, I didn't want to require that everybody use PrintWriter to write to that stream. Currently it looks something like this ( sanitized example... don't bother criticizing my choice of method or variable names ) public void exportRawData...

OutputStream delete file contents JAVA

I have files in who I need to record serialized object. I open ObjectOutputStream for writing in files. If I didn't wrote nothing in file, file content get deleted. I don't want content to be deleted when I make ObjectOutputStream. My code (I use Guice), @Provides @ArticleSerializationOutputStream public ObjectOutputStream getArticleObjectOutputStream(Config config) { Obj...

java - Why InputStream and OutputStream implement Closeable and Socket doesn't?

Have seen this comment in a method: //I wonder why Sun made input and output streams implement Closeable and left Socket behind It would prevent creation of wrapper anonymous inner class which implements Closeable which delegates its close method to an instance of Socket.

java - interface hunt for something like Appendable or OutputStream

Hmmm. I'm trying to write a class that accepts bytes, and would like to implement a well-known interface for this purpose. is an abstract class, not an interface (why???) and that makes me nervous, as I don't know what the consequences are of extending it. If there are no conse...

java - Most efficient way to create InputStream from OutputStream

This page: describes how to create an InputStream from OutputStream: new ByteArrayInputStream(out.toByteArray()) Other alternatives are to use PipedStreams and new threads which is cumbersome. I do not like the idea of c...

java - Missing numbers in the outputstream ( with Complete Details )

( To moderators - This is the 3rd related post of still unsolved problem , now i am posting with all details possible and after doing changes from previous post feedback , though this is a complete post and not dependent on previous 2 posts , if you think this is duplicate please delete the previous posts. thanks ) This is the code of the function public void decrypt(final InputStream cph_in, final ...

memory leaks - Java Outputstream behavior when multiple outputstream objects are wrapped

I have a code that does compression, encryption and checksum on a File Outputstream. Following is the code- private void start() { OutputStream os = null; try { os = new FileOutputStream("/some/file"); os = wrapAllRequiredTransforms(os); //Write to os } finally { os.close(); } } private wrapAllRequiredTransforms(OutputStream os) { if(checkSumRequired) { ...

java - Should I close the servlet outputstream?

This question already has answers here:

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)