Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Apache%20Tapestry%20Interview%20Questions%20and%20Answers

Question: How to get a file from client input to server end in apache tapestry?
Answer:
Make a method like the following a a listener, such as from a DirectLink or whatever.
(The Document is just a class that holds the file information you want to send to the user.)

public void downloadAction(IRequestCycle cycle)
{
    try
    {
        HttpServletResponse response =
        cycle.getRequestContext().getResponse();

        byte[] data = new byte[1024];
        FileInputStream in = document.getFileInputstream();

        response.setHeader("Content-disposition",
          "inline; filename=" +
           document.getFileName());
        response.setContentType(document.getMimeType());
        response.setContentLength(new Long(document.getSize()).intValue());
        ServletOutputStream out = response.getOutputStream();

        while (in.read(data) > -1)
        {
            out.write(data);
        }
        in.close();
        response.flushBuffer();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook