简体   繁体   中英

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 {

@Inject
private RequestGlobals requestGlobals;

@OnEvent("activate")
public void onActivate() {
    try {
        HttpServletResponse response = requestGlobals.getHTTPServletResponse();
        response.setContentType("text/txt");
        PrintWriter out = response.getWriter();
        out.println("hellooooooo");
        out.flush();
    } 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)

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:

http://tapestry.apache.org/tapestry5/apidocs/

more info here:

http://tapestry.formos.com/nightly/tapestry5/tapestry-core/guide/pagenav.html

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM