Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7917009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:00:00+00:00 2026-06-03T15:00:00+00:00

I need to write a String in a file on the client side, however

  • 0

I need to write a String in a file on the client side, however as the Internet protocol does not allow that for Security concerns, this is the workaround I did: I have an AJAX request which invokes a JSP that queries a Database to get a String. I need to show the users a “Save-As” dialog and write this String to the local path they specify.

My JavaScript function:

function openReport(id)
{
    var url = "../reports/reportsHandler.jsp?id=" + id;

    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            //alert(xmlhttp.responseText);
            alert("result obtained");
        }
    }
    xmlhttp.open("POST", url, true);
    xmlhttp.send();
}

In the JSP, I have something like this:

response.setHeader("Content-Disposition", "attachment;filename=report.xml");
out.println(stringObtainedFromDatabase);

I do not see a Save As dialog while I get the alert saying result obtained. This is the first time I am doing this, could you please tell me if I am doing something wrong?

But, is there a way in JavaScript to show users a Save-As dialog and write the content of “div” tag in a file on the Client system?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:00:04+00:00Added an answer on June 3, 2026 at 3:00 pm

    Use a regular HTTP request, not an AJAX (XMLHttpRequest) one.

    function openReport(id)
    {
        var url = "../reports/reportsHandler.jsp?id=" + id;
        window.location = url;
    }
    

    This will send an HTTP GET, not a POST, though it looks like GET is the correct HTTP method to use here anyway, since you’re retrieving data and not actually altering anything on the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In java, I need to write a string into a new file, like 'c:\test\upload\myfile.txt',
I need to write a little program in C that parses a string. I
I need to write a simple file transfer protocol in C++ to upload or
I need to read/write a string of characters using the IBM-1047 character encoding. But
I need to write function for split string with two chars. Ex: Hyderabad Hyd,Test
I need to write a method which will take a string like 1+2+3*4 and
I need to write a TSQL user defined function which will accept a string
I need to write a stored procedure for which the input is a string.
I have a string server.ip=192.168.1.200 And I need to write the above statement completely
I need to continuously upload a generated file from Azure to client's FTP but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.