Periodically call of a Servlet from jsp page (Java) - java

I have a problem and i don't know how to resolve it...
I have 2 .dbf files with ~10000 records (geospatial informations) that i want to read from a jsp page, every time i read 200 records i have to send them to a servlet in some format (i haven't decided yet).
The Servlet must save every record as a Document object in Google Appengine (the limit of 200 records is specified by Appengine api's).
I can't upload the file to server and read server-side cause of some AWT classes not supported by Appengine, then i tried to read the files client-side and send to server the parsed records but i don't know how i can do this.
Someone have a solution to this problem?

jsp, once complied, is nothing but a servlet. That being said, you say:
I can't upload the file to server and read server-side cause of some AWT classes not supported by Appengine
Once you finish reading 200 records, why not insert it into the appengine from the jsp itself. The jsp will run on the server either way.

Related

Java Spring: Real-time status update to the client over REST API

I am developing a web application in Java Spring where I want the user to be able to upload a CSV file from the front-end and then see the real-time progress of the importing process and after importing he should be able to search individual entries from the imported data.
The importing process would consist of actually uploading the file (sending it via REST API POST request) and then reading it and saving its contents to a database so the user would be able to search from this data.
How could I show the real-time progress of this process? I found a tutorial for jQuery, which shows the progress of amount of data uploaded/transferred, but as the most the work is done while processing the uploaded file, I thought I would like a solution where before the line processing I find out the amount of lines in the file and then the user could see a live message like:
Lines processed: 1 out of 10000
It could update/change incrementally, but as one line is processed pretty quickly, showing each number of lines processed is not that important.
Either way, the question is, what's the easiest way to send these messages from Spring REST API to the client?
I found a solution myself and used Web Sockets for that.
I used this approach from the Spring documentation:
https://spring.io/guides/gs/messaging-stomp-websocket/
It could help on sending the messages for each processed line to the front end listener (after the web socket topic/connection is started) but I used a different approach for the data import, I used batch insert so that was unavailable for me, but web sockets are capable of doing that.

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.

Java - File parsing vs fetching html over http

We have a Java class that is supposed to fetch an HTML file and then read some content in it based on the id of certain divs and then return the content to a frontend which will then render it.
Now we have a set of HTML files on a common file system somewhere on the network. Multiple applications will access it. It is like a homegrown GUI help guide for our customer facing screens with a centralized storage.
We have managed to load the html file in 2 ways
Start an Apache web server and put all html files in htdocs. The calling Java class then makes an http call http://someIP:80/helpguide/userguide.html #firstname. This will fetch the help guide related to FirstName field on the screen. The Apache service has to be managed as it is accessed in Live but only accessible within our network.
Create a Shared directory and grant access to it to the Windows logon used to run the Windows service that runs Tomcat where the client facing web application is deployed. Then the Java client class uses new File("<file location>") to load the file and read its content. This works as well.
Basically we have 2 ways to load the html file. Now we are confused whether to use route 1 or 2?
The html files won't be that massive and will be of reasonable size. It may have inline css or youtube video links embedded in them.
Downside of (2) is if we want to include images later it won't work while it should work with (1).
However in terms of performance and efficiency how are teh 2 approaches different? (1) will open a Http socket connection over port 80 and get the html stream back. WIth (2) It will possibly use a File Inputstream to get the file on the server.

Upload file without waiting for its upload and start some other work on the same page

How can we reduce time at the time of uploading a file from jsp to servlet in apche tomcat and put it in queue and start some other thing at the mean time while uploading of file is going on
You can make the call asynchronous using #Asynchronous
The server should be able to handle any (reasonable) number of simultaneous requests: just let the upload happen and do something else!
Now, to do that on the "same" page as the upload is not possible if you are using plain-old HTTP POST with a form. Instead, you'll have to use one of those Flash-based upload tools or maybe there is one in Javascipt you can use that will send the upload some other way (XMLHTTPRequest?). Then you can have the upload run but the page itself is still functional.

Load custom data from HTTP web page

I need to read some specific data in an HTML web page, from Android.
I wrote class that build the exact HTTP address. Now I can load the page and parse the data I want, but since bandwidth is expensive on smartphones, I would like to load just some custom data off the HTTP web page, to save memory.
Is this possible? How could I do it?
Cheers guys :)
Your alternatives are
Build a Proxy and host it on your server, which will parse the web page, and return relative data to the smart phones.
Read the response stream and once you get all the data you need stop reading. this is depended on how large the page is and where the relevant text you need is located.

Categories

Resources