Solved

want to get download prompt

Posted on 2011-03-07
11
518 Views
Last Modified: 2012-05-11
Here is the Jquery request sent to MyAction class

$.ajax({
                  type: "POST",
                  url: "MyAction",
                  data:  $('form').serialize(),
                  cache: false,
                  dataType: "html",
                  success: function(result){
                  
                   // what to write here so that I can get doc download prompt
               
                }
 });
 
 


Struts MyAction  retruns "result.jsp"
      
      
result.jsp
------------
 <%
response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
// blah
// blah
%>
0
Comment
Question by:cofactor
  • 7
  • 3
11 Comments
 
LVL 2

Accepted Solution

by:
adeelshahid earned 500 total points
ID: 35056576
You need to submit your request to an iframe that would popup the download prompt.

This requires response header's to be pushed out which shows the download prompt.
0
 

Author Comment

by:cofactor
ID: 35059322
I'm doing a JQuery ajax form submit.  Instead of getting a html response , I'm trying to put a download prompt .

Please see the question again . What changes I need to do so that Ajax form submit can pop up a download prompt ?

0
 

Author Comment

by:cofactor
ID: 35063595
comments please.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35068177
Do one thing jsut another jsp file in the ajax call that jsp having response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");

its show the popup window !! (but you should all the same value in that jsp )
0
 

Author Comment

by:cofactor
ID: 35082068
>>>Do one thing jsut another jsp file in the ajax call

how ? how do I do that in my code ?

>>>that jsp having response.setContentType("application/doc");

I have this result.jsp
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35082097
>>>>>>success: function(result){
                 
here u can call the jsp like form submit
document.formName.action="MyAction.html?fetch="+test;
  document.formName.submit();              
                }
so this will go to ur actoion calss there you can redirected to another JSp .
0
 

Author Comment

by:cofactor
ID: 35082170
>>here u can call the jsp like form submit

success: function(result)--->This is the result section returned by the action ..why do we call action here ?


Do you mean I need to call the Action here again ? Also I'm doing a JQuery AJAX post submit.

Please see the code again .
0
 

Author Comment

by:cofactor
ID: 35082262
I have removed Ajax code and put it other way...I'm using the same result.jsp as my return page when action gets called.

$('#exporttoword').click(function() {
			
			alert("exporttoword");
			document.forms[0].buttonName.value="exporttoword";
			document.forms[0].hdncreatePage.value="3";
		
	        
			var ifi=0;
			var container = document.getElementById('mainAction');
			alert('container='+container);
			container.innerHTML+='<iframe id="ifi'+ ifi +'" height="55" frameborder="1" width="55" name="ifi'+ifi+'"></iframe>';
			document.forms[0].target = 'ifi' + ifi ;
			
			document.forms[0].action="MyAction";
			document.forms[0].submit();


		});



		<input type="button" id="exporttoword" class="submit_btn_base" value="Export to Word"> 

Open in new window



This works ...but issue is , when I click button second time , the click function is not called and so I dont get download prompt on next click.  Can we find a workaround for this ?
0
 

Author Comment

by:cofactor
ID: 35092281
I have used Iframe and have a tweak  in my code . problem resolved.
0
 

Author Closing Comment

by:cofactor
ID: 35092285
I had a couple of tweaks but this comment helped
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35092372
Gd....
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 37
How to convert String matching to regex in java 4 34
How to determine if a string is a valid SHA value 7 34
Java: anonymous class 4 22
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question