Browser timeout waiting for JSP to finish Java method - javascript

I really can't solve a problem: I've finished to write a web application during my internship which allows me, after a series of queries to Oracle DBs, to create my own tables on MySQL, then export the results in a custom fancy to XLS or PDF. The server side is in Java, the client side is in Javascript, some JQuery, and obviously HTML5. The server is set up with Apache Tomcat.
The method I use to run the queries and then export the results to a direct-download file (nothing stays in local, I use OutputStreams) is written in a jsp which I call by a button press from index.jsp.
As I was in local on my laptop with my own Tomcat, the browser waited patiently for the Java to end, then returned the generated files. Right now, after the remote deploy in a local server, the browser times out "casually" giving an err_no_response code. This happens both in Chrome and Firefox. The queries do take from 2 to 12 minutes to be done, and that's the problem.
I tried both polling with Ajax and websockets, but none of them worked: the firewall is in the way and I can't tunnel in a proxy it seems.
Any idea on how to keep the page alive while the server is running? Thanks.
PS: I can't edit indexes on the Oracle tables, nor alter them in any way. The queries are already quite optimized.
Also, I know I'm doing a lot of mistakes (plain Java code in JSPs...), yet this is the best I can do for now. Changing the whole logical structure of the code is hard at this point and I just need a painless solution to make everything work.

Related

Converting simple php web app to LAN only

Apologies if this is not the best tag to use. I'm after some basic thoughts on the best way to do the following without using the net.
I've been asked to build a simple ordering service for a busy takeaway. They're looking for something like you get in McDonalds ie a large screen showing the status of order numbers.
I've created a basic system in php/mysql which consists of 2 pages which look very similar however the staff one has the ability to change the progress when an order item is clicked. The 2nd page is the one that will be displayed on the customer screen and simply queries the database and outputs the results, the page refreshes every 10seconds or so.
The idea is that the customer page will run on a large screen in the restaurant while the staff page will be on a couple of touch screen tablets. As there is no need for internet usage I would like to move this to an internal server but am not sure where to start?
Can I simply setup a server using an old PC, install php and mySqL on it and set it running? Do I then just reference the IP Address of the "server" on the tablets ie something like 192.1.1.1/staffpage.php?
Or is it a bit more complicated than that?
You have the right idea.
I would suggest building a LAMP stack (Linux, Apache, MySQL, PHP) on a cheap linux box. As ivanivan suggested, a Raspberry Pi would be ideal.
There are many tutorials on setting this up with the Pi and Linux.
However, if this is too technical then using an old computer with WAMP/MAMP would also work.
When the server is setup and running on your local network using 127.0.0.1 or localhost, then the ip address of that machine should be reachable by other devices (assuming your firewall allows it).
You could simply load the webpage in a fullscreen browser and use client side javascript to refresh the page every 10 seconds.
Or if you wanted to get clever, you could use ajax or websockets.
On a side note: Another completely different option could be to use a node.js server on a Raspberry Pi and do away with Apache, PHP and Mysql all together.
I hope this helps.
yes you can use the localhost and you need a corn job to refresh the page every 10s

Altering a server file through javascript code

So I have a setup of a tablet connected to a Raspberry Pi computer. I want to be able to have a webpage hosted on the Pi change the contents of a file also hosted on the Pi (which will be used in a python script that i have written). I tried having the file inside a hidden iframe, but while my javascript ran, it didn't ever actually change the contents.
How can i set up communication between the webpage and the server files? I know nothing about jQuery in the slightest, but if i have to use it, I will.
While you can actually do something with files in HTML5, you must know that Javascript is a client-side script. In other words JS 'runs' on the persons browser and not really your server.
Languages like PHP actually run on your server, and therefor are able to achieve what you want.
I'm not THE Javascript expert, and you might even be able to modify a server file with JS but it will be 'hacky' and have a poor implementation and you might need to run a sort of API on your server that actually does the changing..
Save yourself the trouble of doing it like that and pick the right language for the job. I would suggest PHP. Its fairly easy to set that up and run the website. PHP has enough ways to create, view and modify files on the server itself: http://php.net/manual/en/book.filesystem.php

Is it possible to change script running clientside on a webpage?

So I'm playing a game online on my laptop and it is a pretty simple html5 game but the optimization is nonexistant. The game with a few circles on my screen is using 85% of my cpu.
Logically, I started profiling the game and was trying to figure out if I could optimize it for my laptop. Now, what I'm wondering is how could I run the game but with a tweaked version of the JS script that is running.
If I try to save the page and run it from my laptop it of course has CORS issues so I can not access the server.
Can I somehow change the script a bit which is executing in my browser but while still staying "inside the webpage" which is running so that I may normally make XHR requests to the server?
Also, although this is not in the title of the question, can I somehow proxy the XHR request to my script but while not breaking the CORS rule?
Why is it so different if I run the same thing from my browser and from a saved HTML on my desktop? I have the same IP and am doing the same thing but from the url it "feels like" I'm running it from somewhere else. Can I somehow imitate that I'm running "from the webpage" but instead run it from a modified saved html?
You could proxy, given there isn't a cross domain protection mechanism or some sort of logging in (which complicates stuff).
What you could very well do is use a browser extension which allows you to add CSS, HTML and JavaScript.
I'm not entirely savvy on extensions so I'm not sure you can modify existing code but I'm guessing that if you can add arbitrary JS code you may very well replace the script tag containing the game for a similar personally modified script based on it. It's worth a try...
Link to getting started with chrome extensions
Update:
If you're set on doing it, proxying ammounts to requesting an URL with your application and do something with the page (html) instead of the original source. I assume you want to change the page and serve it to your browser.
With this in mind you will need the following, I dont know C# so you'll have to google around for libraries and utilities:
a way to request URLs (see link at bottom)
a way to modify the page, you need a DOM crawler
a way to start said process and serve it to your browser by hitting your own URL, meaning you need some sort of web server
I found the following question specifically on proxying with C#

Running Browser as terminal process

I am trying to do some high scale testing with my nodejs server so I want to find out how its possible to run the chrome browser on the terminal, similar to how nodejs runs the server.
I want to have a few hundred on a single machine which is why I want to avoid running the actually browser tab instances. It also needs to specifically be google chrome.
Right now Im trying to figure out how this is possible, even if it's just somehow running the messaging javascript from the terminal.
Can someone please point me to the right direction :]
Have you looked into Request, CasperJS, or PhantomJS? I think they may be just what you're looking for. Phantom is a headless browser that can browse webpages for you (useful for testing, taking screenshots, and taking actions on pages for you). CasperJS can help you out with that, as well, and Request allows you to make http requests from your server, rather than client. If you need to search/ traverse the page your server gets back, you can also use Cheerio, which is pretty much jQuery for your server.
Hope that helps!

making exe form HTML and Javascript

I was wondering I have PHP based server side stuff that accepts ajax requests and sends back JSON for JS. And I have HTML and JS based "client" now I would like to create exe(windows aplication) that would look the same as the "client" in browser but without browser. Preferably somehow grab that HTML and JS and "compile it" to regural client that would still send out AJAX calls and procesing JSON data.
Edit:
To clarify things:
Server(on webserver) is PHP procesing incoming AJAX calls and diplaing JSON as result.
Client(what I want to convertt to exe) is HTML and JS(Jquery) page(application).
I want for user to have option two to dowload client for windows so he/she dont have to use browser.
With https://electron.atom.io/ from Github you can develop Windows, Mac and Linux applications with Javascript, Html and CSS. You can also build mobile application with your web development skills. https://cordova.apache.org/.
You can use Electron, but if you just want something quick and easy to use, try Scriptonit. It's exactly for this kind of use. (Check out the documentation and the examples to see if this is the one for you.)
It's basically one exe plus a few sidecar files in a folder called app/, then it just works like a local browser without the frames & head. Also, it can access local files and run OS commands, even capture their output.
Side note 1: Yes it's mine, as you can see on the link - but no, that's not why I'm recommending it
Side note 2: It's 0.9 so it's not perfect, let me know if it misbehaves.
I don't think you can make a desktop application with markup languages. but then am also a newbie in this stuff but what I think you need is to develop a GUI in a programming language like java for example Swing docs.oracle.com/javase/tutorial/uiswing/ to mimic the apearance of your webpage. Then connect to your server by socket programming.

Categories

Resources