Multiple responses from a single HTTP request - java

I have a Java Web Application. When a user clicks on a "Retrieve" button they expect to see 3 new tabs open in their browser with a different PDF document in each tab. The PDF documents are generated from the server.
I know this can be accomplished by sending 3 requests from Javascript within the html page, but does anybody know of a way to accomplish this with a single request to the server or is that not allowed?

Related

Web Sockets in multiple page web project

i'm looking for nice tutorial or, maybe, some tips how to implements web sockets in multi-page web project.
For example i have welcome page and some link here. When i press on link i should be redirected to www.domainname.com/anypath with another fields and data.
To interact with the server i need to use web-socets. How many Server and client endpoint i should create? New endpoint for each page, or only 1 endpoint for each page?
I'm really trying to research it in google but there only tutorials with one page without any user navigation.
in simple realisation you create a websocket connection per each page, but if want optimize your application possible create one connect per all tabs.
for this optimize your can see how this realized in my open source comet server in file CometServerApi.js
In two words in file CometServerApi.js establishing a one connection to server from first opened tab ( i call this master tab), and other tabs send and receive message through master tab
For communications between tab i use event onstorage emerging on all tabs when i write any data to localstorage in any tab.

how to get event of change state of tabs or page

I have one application who has two parts one is display module which is web based using j2ee and other is my backend service module which is on java. I have one page which has 4 tabs which has graphs. When click on tab, it sends start request to my backend application to start sending live data on my page. Problem is when I change the page to other page, my backend service keeps on sending the data. I want some way from which I can send stop request to my service program, when I change the page or close the browser. Please provide me some idea.

Saving current page as html file using java/jsp/jquery

I have a informative web page in my spring based web application which need to be saved as html/downloaded.
My requirement is to save/ download this opened webpage on click of a button on same page.
I used below code in javascript.
document.execCommand("SaveAs",true,"C:\Saved Content.html");
But this is only working in IE and not in other browsers.
Kindly help on this.
Simply no. JavaScript/Jquery is restricted to perform such operations due to security reasons.
The best way to achieve this, would be, to send a request to the server that would write the new file on the server.
Then from javascript perform a POST request to the server page passing the data you want to write to the new file.

how to send file objects to servlet using json

I am new to web programming. My web application can upload files (uploaded by drag and drop method in javascripts ) and i want to retrieve them in servlet using Json . servlet file only needs the contents of the text files to do the calculation.
Can any one suggest how to do this ?
softwares used - netbeans ,tomcat
Thank you.
I'm not quite sure if you mean rendering your files in servlets or actually downloading them from your browser. I'm going to assume you mean rendering them. If so, then what you have to do is set up a URI which is associated with the content you want to render. Let's say this is a simple "hello world" rendering in the browser. what you would do is set up a URI as such:
localhost:3000/helloWorld.html.jsp
What you do on your back end is then wait to receive a http GET request to "/helloWorld.html.jsp" page, and then have your router send over the correct page. Luckily, with tools such as tomcat, the routing from local host is straight forward enough, and as your comments mentioned this is simple enough to do with the ample resources on the web.
Also an important point, you don't need JSON when using servlets (if i understood your problem correctly). If you want to send over data in a JSON format, then all you would do is modify the above steps to listen for "/sendJSON.html.jsp" (this could be an empty jsp), and you send over JSON from your back end in your response.

How do I use a GWT RPC to save a file on the client side?

I'm looking for specific code on how to send a file from the server-side of a GWT application so that the client-side user can save it on his machine. Currently, the app allows the user to upload a file, reads it, and puts certain values from the file into editable text boxes. When the user hits the "save as" button, it collects that edited data, puts it back into the file string, and sends that string to the server, where I want it to be put into a file and pushed back to the user on the client side, so that they can save it to their machine. How exactly do I accomplish that?
Sorry if this seems like an obvious thing, but I'm relatively new to GWT and java in general. Thanks!
I think that you want the way for download a file using content-type from server using GWT.
The easiest way that I have found is create a iFrame :
import com.google.gwt.user.client.ui.NamedFramerdddccvc
...
NamedFrame iframe = new NamedFrame(frameName);
iframe.setVisible(false);
parent.addChild(iframe);
iframe.setUrl(url);
It's important that the url from the server return a page with content type "text/plain" or using the valid requested.
What you can do is create a servlet, that generates the text as content and set the matching mimetype for the content. In you app you can call this servlet via the by Fernando suggested IFrame method.
There are many suggestions here on Stackoverflow on how to do it. Search for [java] file download serlvet and you will find lots of examples/guidelines on how to do this.

Categories

Resources