Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By amateur83

Thread: response.setContentType

  1. #1
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default response.setContentType

    I'm using Tomcat

    I have my servlet:
    Java Code:
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();

    What I want is the browser able to prompt a 'Save As' screen instead of display my plain text directly in the browser.
    Any ideas?

  2. #2
    amateur83 is offline Member
    Join Date
    Jun 2007
    Posts
    3
    Rep Power
    0

    Default

    response().setContentType("application/msword");
    //set header name
    response().setHeader("Content-Disposition","attachment; filename=DocumentName" + ".doc");

    Writer writer = new BufferedWriter(new OutputStreamWriter(response().getOutputStream(), "UTF-8"));
    writer.write();
    writer.flush();
    writer.close();
    sherinwip and Ahmar like this.

  3. #3
    Ahmar is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Re: response.setContentType

    @amateur,

    i am facing the same problem. i want to get an object of the file in my javascript instead of opening a "save as" dialogue box... Is it possible to get file objects from servlets along with other data into our script.???

  4. #4
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: response.setContentType

    You can also preview
    PHP Code:
    response().setHeader("Content-Disposition","inline; filename=DocumentName" + ".doc");

Similar Threads

  1. response.sendRedirect(url)
    By mutuah in forum Advanced Java
    Replies: 2
    Last Post: 08-07-2007, 02:56 PM
  2. help with response.sendRedirect method
    By katie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 03:22 AM
  3. response.sendRedirect problem
    By christina in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-03-2007, 06:23 PM
  4. Velocity / XML response
    By sabatier in forum XML
    Replies: 0
    Last Post: 07-24-2007, 02:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •