Updating webpage info from socket (JSP) - java

im starting to get on web development and I can use some help with this issue:
Im trying to do a web table where I can follow changes in market values.To do this im using a java API created by the company that provides me with the data; this API connects through sockets to a gateway server on my company that receives this info directly from their market databases.
The java app receives the data in real time and every 5 minutes creates an .txt document on the server. This .txt document is then read by the html page using a JS script I found.
I now this is a really crappy way to update the table and I want know if its possible to get the data in realtime directly to the page using JSP.
Thanks for your time.

In my opinion the cleanest implementation would be:
Database that holds the values you wan't to show.
Scrip / procedure that calls the API and stores the values in your database
Your page reads the values from the your database.
I wouldn't go for a real time solution, because then you have to wait for the API call evertime your web page is loaded.
On the other hand, it's possible to parse an external webpage / api with php, and include it directly in your page. Without the database in between.
But again - Then you'll notice a slower responce, and make an unnecessary API call evertime your page is reloaded.
XML parsing with PHP: http://www.php.net/manual/en/book.xml.php

Related

compatibility between React.JS and java

I have a question that tapped me. can someone help?
Here is my question:
can react front end be used with java?
If yes How is it possible?
Thank you in advance
Yes it is possible to use react front end and java as back end.
Let us assume you want to build simple school management application with following feature.
In home page we want to show simple three tab student teacher and admin.By clicking over each tab it should show a page containg that partucular user realted data(userName, picture, address).
We will be having simple Mysql database to store user information.
Use React:
To build this I will use express as framework to use React.In React I will be having component HomePage and UserInfo.
When we click any tab on home page we need to fetch data from database.
To call an external api I will use redux and save data in redux store.
Your frontend will be running on express(assume on localhost:3000)
Use Java:
As backend Let us assume we want some manipulation of data so we will use java(use jersey to make rest apis).In java we can make connection to database and fetch data.Using java we will make a post api taking user type which return user data in json format.This json will be stored in redux store.So in new page after clicking I will iterarte through this data and show in page.
Your backend in java will be running on tomcat(assume on localhost:8000)
Yes of course, in fact java and react or any other front-end technologies should not have a problem communicating to each other. You may want to do some readings on Representational state transfer (REST).

What is the best way to store text data in a file/files so it can be used in various platforms?

I'm developing a knowledge base java application, where I can store and retrieve annotations with its title, date when the note was created (SQL datetime), content, tags about the annotation, etc.
It can be done easily with a database (I'm using SQL Server 2014), but the main problem is that the server is running on my own PC and it has to be always on and running the SQL Server. Also, I would like to extend the application by storing and retrieving this kind of data on mobile apps for Android and iOS.
Is there any other way to store that type of data in some files so it can be uploaded to some cloud storage like Dropbox ? After storing it on Dropbox, all I would have to do is sync the app with dropbox, get the files and read/write stuff.
UPDATE: Thanks for all the answers they helped me a lot. The best solution for me is to replace SQL Server with SQlite, as Gabe Sechan commented. Now I can make changes on the database without the need of a server running 24/7 and I can use the same database on Android and iOS apps.
You can use just a basic ajax call to pull content from a Dropbox "public" URL.
function(contenturl,intoselector,callback){
if (contentwindow.currenttopic!==contentID){
jQuery.ajax({
type:'GET',
url:'//www.corsproxy.com/'+contenturl,
dataType:'text',
async:true,
success:function(data){
intoselector.html(data);
if (jQuery.type(callback)==="function")
callback();
}
});
}
Notice that this example pulls through corsproxy so that you don't receive any XSS errors, so the url you pass needs to not contain a protocol itself.
If you want to pull a JSON or XML string that is stored in the file, then you might need to play around with the dataType and contenttype options in the ajax call.
This can also be done using Google spreadsheets:
Reading:
Create a spreadsheet and publish it on the web
Use one of the many available Javascript libraries for pulling data from Google spreadsheets:
http://jlord.us/sheetsee.js/ (which uses Tabletop.js)
http://chriszarate.github.io/sheetrock/
Writing:
You can use a Google app script for writing to the spreadsheet (reference) OR
You can create a Google form linked to the spreadsheet and simply fill the form from your mobile app whenever you want to add some data to the sheet (reference)
Of all the cloud services, when it comes to Android, Dropbox's Sync API is one of the easiest to implement. Do you need specific code examples on how to sync with Dropbox?

How to read or write data from a MySQL cPannel Database in Java for an Android App

Any tutorials out there on how to send and received data to and from a MySQL database hosted on a server using cPannel? I'm trying to make an android app that connects to the internet, and it needs to read and write data to and from the hosted database. The database is a MySQL one and is hosted on godaddy. I've been on the internet all day today looking, so any help would be greatly appreciated.
Well you need to write a webservice which will get the data from your mysql database and send it to your android app.
First of all you need a server which you have already. Create space to write php scripts there to interact withe the database that is hosted there.
Second Write a php script on your server which can retrieve the required data from the MySQL database. Encode the retrieved data inside a JSON object and send it back to your app. From your app you have to call the URL where the webservice is hosted, and the php script will do the interaction with the database, retrieve the results and send it back to your app in JSON.
Third - Follow the same method to send and retrieve data to server. Create multiple webservice as per your requirements.
This tutorial excellently illustrates what you are looking for. This example uses a local server. You can skip some of the steps there. Hope it helps. URL: http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
If you still got any questions, comment below. I will be happy to help.
Thanks!

Storing / Retrieving App Data Online using Android

I am new to Java and Android. I am just beginning work on an app that will save information to a server that someone else from within the same company can retrieve using the same app from a different android device. I know how to simply store data on a server using simple php scripts but this is a bit more complex and involves one user writing information to the server, while another user can see / download it. Within a company there would be multiple users who have acceess to this data. So my question would be, whats the best way to implement a company-wide database that ONLY members of the same company can have access to? Sorry if this seems obvious to some of you. I am just getting started and I have 7 books on android programming and none of them describe how to do quite what I am trying to do.
To do this you need to use Android network services to access data. In other words to retrieve a networked database information your device will connect to your service with a specified URL and arguments. In turn, the service will reply with the required data, say may be in XML format. All your app needs to do is parse the XMl and display the date as desired.
Same thing applies to putting data into the server, in this case however the data will be sent as arguments to the network service URL and the service will handle the persistence to a database.
My advise is to do a Google search of the keyword "Android Network Services".

How to avoid temporary file creation on server-side when pushing back full HTML content to clients?

In a server-side application running on Tomcat, I am generating full HTML pages (with header) based on random user-requested sites pulled down from the Internet. The client-side application uses asynchronous callbacks for requesting processing of a particular web page. Since processing can take a while, I want to inform the user about progress via polling, hence the callbacks.
On server-side, after the web page is retrieved, it is processed and an "enhanced" version is created. Then this version has to go back to the user.
Displaying the page as part of the page of the client-side application is not an option.
Currently, the server generates a temporary file and sends back a link to it. This is clearly suboptimal.
The next best solution I can come up with inolves creating a caching-DB that stores the HTML content together with its md5-sums or sha1-ids and then sends back a link to a servlet, with the hash-ID as an argument. The servlet then requests the site from the caching-DB.
Is there any better solution? If not, which DB-backend would you propose? I'm thinking of SQLite. Part of the problem to be solved is: how do I push a page <html> to </html> back to client side?
If true persistence isn't required how about using something more temporal like memcached instead of SQL? Calling semantics are pretty clean and easy - and of course you can expire the data manually, ttl, or # restart.
Instead of creating a temporary file, filling it up, and then sending a link, you can create a memory buffer, fill it up, and then send that as the response (serve it with mime-type 'text/html'). If you don't want to send page-buffers immediately, you can save them for later in the user's session. If you're worried of taking up too much memory that way, you may want to keep only a certain number of page-buffers around in memory, and write the rest to disk for later retrieval. Using a DB sounds like overkill (after all, there's no relational information involved) - but it would solve the caching problem nicely.

Categories