This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
In my application there are several buttons in various pages which does the same functionality of downloading records into an excel file.
All requests for download go to Download.do?status=X where X varies. Now based on X the data present in the HttpSession object is filtered and is written into an excel.
If in case there is no data existing in the HttpSession object after filtering is applied then I was thinking about showing an alert box which will inform that there are no records to be downloaded.
I have written the below code to achieve that.
PrintWriter pw = new PrintWriter(response.getOutputStream());
"alert('There are no records to be downloaded')" +
But the problem with this is that, the screen which was previously available goes blank and only the alert pop-up is shown. I want the previous screen to be as it is and only the alert box to appear. As in case of an excel which comes as an attachment on setting the ContentDisposition header attribute in HttpServletResponse
can anyone please help me on how I will have to achieve this?
But my problem is various jsps call the same action Download.do. Each jsp needs a different set of data that has to be downloaded so I make use of a 'status' request parameter added to the query string (for eg. Download.do?status=E). The value of status varies.
So based on the status value when I don't get any records, I wante to return back an alert message which has to appear before all jsps and the screen state at the background shdn't change.
Still, I put my approach for the same if you want to do that,
what I thought of doing this is:
1. Get the incoming JSP page
2. Try to embed the "alert" JS tag into it (Its hard to do, have some Googling) OR simply append the JS
3. response output this new modified JSP
Isn't that hard ?
The best and standard way is always been the ActionMeassges in Struts.