Displaying the database table on the windows screen in real time - java

I have a database table which is running on a remote host. I need to write a program to display this table in a windows form or on a html page on the desktop screen. The program needs to run at equal intervals (say 30 min).
After every 30 min the program will run and the data needs to be overridden on that form or page. There could be any approach to this. Prefer Java.

Two different ways of doing it (really three, the third one being running a java-applet)
The coarsest way is to put a refresh header in your html like
<meta http-equiv="REFRESH" content="600;URL=page.php">
where you have to exchange page.php with whatever is the address of the page you want to reload (this says basically after 600 secounds, load page "page.php" You will not be able to sync this to the dbupdates, as the refresh happens a fixed time after the page load. So how often you reload will be a compromise between your server load and how long delay you will accept. Also, you probably will want to have this as a separate frame (ooouch!) if some information is to be entered on the page.
A bit more contemporary, use javascript ajax and timed events. You want to juse jquery or prototype.js or another library for that. Here you may be able to sync the reloads to the database updates, given that the real time clock on the workstation and the server are in sync.

Related

Rookie question - Can I write a script that executes actions for our internal cloud software?

I work for a big global company (100 000 employees) and we have an internal software (its a database), this service/softwareh can be accessed from all employes via their internet browsers.
I need to change about 200 names in this databas and it is a VERY repetative work which takes time due to the cloud service is sometimes very slow. It usually takes 20 minutes to change one name... and I need to do 200 names!!
I have asked if its possible to just write a script that picks up my information from an excel sheet, then open ups the internet explorer, go to the site, click on all the correct buttons and paste the correct values.
The answer I got was "It is not possible to write a script to alter the database, you would need to go via IT department and via the correct programmers". But I assume that is if I want to superbig mass-update the database? I just want to get rid of the repetative task so I dont need to sit and wait 20 minutes x 200 names.
I guess my question is: Is it possible to write a script that performs actions via internet explorer EVEN IF ITS AN INTERNAL SOFTWARE/CLOUD SERVICE we are visiting?
Please - Im very very new to coding, as you might tell.
Welcome to stack overflow! It's definitely possible to automate those sorts of tasks using scripts, but if you're going down that route I would suggest that automating via internet explorer isn't the best option. Perhaps your IT team could look into creating a tool to access and modify the database directly instead? That would likely be much faster and less convoluted to set up than automating via a web interface.
However, if you're set on using a web browser to automate tasks I would suggest that you start by looking into basic javaScript tutorials and jquery to get started with web manipulation (jquery is an addon library for javascript that lets you set up interactions with web page elements in a friendlier way)! Using javascript you can write scripts to simulate button clicks and enter text values, which sounds like what you're looking for.

Dialog box in Spring MVC controller

Is there a way to display a (preferably modal) dialog box in an servlet controller ? If it isn't modal that is something I can deal with (!?) as long as it initially appears above the browser.
Essentially I have a form with a table and 2 buttons on it. One button takes the user to a different place in the workflow and is irrelevant to this question (just to explain why the other one doesn't 'go anywhere').
The other button currently goes back to an MVC controller, calls some code to export the table to excel and then reloads the web page. This is all working okay except the way I am calling the dialog box is calling it underneath the browser. I suspect this is because I am sending null as the frame but I'm not sure what to put in its place ?
JOptionPane.showMessageDialog(null, "Export Completed.", "Excel Export", JOptionPane.INFORMATION_MESSAGE);
Many thanks.
I am not too sure what you are trying to achieve from your question and without any code examples. However, presumably what you are doing (guessing here), is that you are trying to export some data from some data source and convert it to an Excel file. You have to keep 3 things in mind.
Web applications work via HTTP requests and responses. So the only thing a Servlet can do is send back an HTTP response that indicates that the export was successful. Whether you use a traditional page, or maybe use AJAX to avoid refreshing the page is purely your design choice. You could also start with a simple page and then change to AJAX combined with JQuery later once you get used to what is happening.
Exporting the excel sheet to the server does not mean that your client has access to it. Speculating here, but you will probably need a mechanism for your user to get the file. One simple approach used by many webapps is to actually send the Excel file as the Servlet response itself. So what would happen is that when the export is completed the browser starts receiving the file and the user sees it downloading. From your servlet you will just need to set the right mime-type and set the content-disposition header to state that the file is an attachment (so that the browser downloads it as a file).
httpresp.setContentType("text/csv");
httpresp.setHeader("Content-disposition", "attachment; filename=\"export.csv\"");
You will probably also need to set the file size. There are various full examples on SO if you look for further details.
When performing these operations remember that users can interrupt the browser or refresh. If the user presses F5 he might cause your application to do the export again. One common approach to this is called 'redirect-after-post'. Basically you redirect the user to a page which just displays the outcome, without performing the operation again. This way if he presses refresh, he is just refreshing the page with the message.

GWT low performance

as an introduction: I am new to GWT and coding, so my questions may appear basic.
I made web app using GWT, Maven, Hibernate, IntelliJ IDEA. I deployed app on my own Tomcat server (I have separate computer for this: HP ProLiant ML310e Gen8 v2 4-Core 3.1GHz 4GB DDR3 + HDD 2x1TB SATA).
It is simple page with 5 tabs, and it has one .png 48 Kb image as header. The view that is loaded initially has:
2 Labels with few words,
CellTable containing 20 rows (content is obtained from database through RPC, from database)
4 Buttons (for table paging)
This view has almost no content, it has following panels just for exact layout I want:
3 VerticalPanels, 6 HorizontalPanels, 1 Tree and 1 Grid
The problem is: . When I run URL first time, it takes 1:09 min to load anything. And every next time I paste URL it takes about second to display app.
(after page loading everything goes smoothly, just a second to display widget)
I read this article: http://blog.trifork.com/2007/11/30/optimizing-startup-time-for-gwt-hosted-mode/ , but server runs the app in production mode (GWT.getScript() returns true). I also ran through a few topics on stackoverflow, but I don't see what loading time is "normal" for small size apps.
If time above 30 seconds is required to run anything, then GWT appears unacceptable for typical user, who may think that the link is broken at first time... I don't know how it works - is GWT rebuilding and recompiling the page for every new user request?
I don't know how it works - is GWT rebuilding and recompiling the page for every new user request?
No.
GWT uses caching. The initial loading time is really depends on many factors.
When user/browser requests for the very first time, all the resources related to the page loads. That takes few seconds to load and really depends on your internet speed.
Once the complete page loaded and if you are requesting new page/ reloading the current page, all the resources won't load this time.
Coming to the part that rebuilding and recompiling for each request is wrong. In Gwt there are permutations which are specific to each browser. Every major browser have it's own permutation. If you request from Mozilla for example, permutations related to Mozilla loads. These permutations actually generates at compile time of project which you done in your IDE before deploying the project.
Once the request hit the browser, for very first time these all files related to the specific permutation loads into browser and cached in browser. Form next time on words you won't see any new files loading in to browser (you can see that using your firebug).
Using code splitting, lazy intializations and data compression techniques.
Continue reading .....
check yourapp.gwt.xml file if you have inherited some modules that takes time to load.
if so, during first load it takes time and the way gwt works is it loads and maintains a cache for future loads, which answers your problem about taking time to load at first and seconds to load next time.
And gwt does not rebuild or recompile the page, simply displays the page you have compiled
Take a look at GWT.runAsync, this will help you to not load everything on startup, just what you need :)

Java Temporary file for Memory management

I have a huge data that has to be displayed in a page retrieved from database table. The table is regularly updated with new data and page has to display the latest data whenever refreshed. Since, the page is loaded with heavy loads of data it takes time to load (2-3minutes) and sometime it suffers from only displaying white page.
So, what I need to do is create a temporary file in server which stores this data from database and the page will extract info from this file. This file should be reloaded with new data in each 10-15 minutes so that till 15 mins page displays the old data but after 15 minutes if page is refreshed it shows the new data.
Hope my problem will be solved with the above idea but I am only limited to above theory. Please provide me solution how it can be done and any other better idea than the above. if any java code sample that would be great to solve my problem.
Thanks
Now you are propably using a lightweight webserver (guessing from the fact you are talking about pages loading white)
But if were using some java ee application server like glassfish, you could have a scheduled task running every 15minutes that loads the data and stores it into a file.
http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html
Maybe Quartz is the answer for you:
Scheduled task in a web application?
Or maybe you are not using a webserver/appserver at all and my answer completly invalid.

Can I get result of a GWT async call before the page is rendered?

I have a GWT page with a listing (from the datastore) on it. I understand how I can get this listing after the page is loaded, with an async call, but I want to make sure that when the page is loaded initially, it has valid data in it. Otherwise, the page loads most of the way, and then the listing is filled in, which leads to a choppy load, and a longer time the user needs to wait before the page loads.
So, how can I get data from the server into the page when it loads? Is there a way to call the server-side service from the constructor of my UIBinder class? I can't call the actual service implementation, since the client-side code can't reference the server-side code, right?
Surely this can't be a unique need, but I can't seem to find any tips on Google (though I might not be searching the right terms).
What I've done in my own project to solve the same problem is to use JSP to embed the data that I need into the page source as javascript objects. That way the data is already there by the time onModuleLoad() is called. Google have a bit of documentation on how to read javascript objects into your java code.
Obviously you'll need to know a little bit about jsp as well.
You could hide your whole page content until the data is loaded to avoid the choppy effect.
But the most user friendly way would be to display a loading message on your page load. Then in the success and failed events of your async call, after the data is bind, hide the loading message.

Categories

Resources