compatibility between React.JS and java - 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).

Related

Best way for communication between MySQL and Java

I'm developing a game in Java and I need need store and get data from mysql database.
Currently I have login credentials saved in my Java app source codes and I'm using some library for the communication. But I think that this is a really unsecured way cause of credentials saved in the Java file.
I was wondering what if I do it through some server side PHP scripts which would just get some information and do what is necessary. But again somebody can get that link and do some evil.
I also thought about creating a new database and mysql user for each user registered. So there would be central database where would be just informations for game and it would be read only. So no security problems. And user informations would be saved in his own database and only he would have login for it. But I see one problem, what if I'll need get some information from another user?
So I was wondering what is the best way to keep it simple and secured?
Define a set of services (RESTful will be good) in server side (through PHP or Java or another programming language) that communicates with the datasource (MySQL or another). Then, from your client, consume these services. Now, you can assure the client and server points for communication like authentication and authorization to consume the services, you can use OAuth for this.
also thought about creating a new database and mysql user for each user registered. So there would be central database where would be just informations for game and it would be read only. So no security problems. And user informations would be saved in his own database and only he would have login for it
This is a no go. Since it's a game, you will have to maintain a single database per user. It's highly costly and you will have more problems than just retrieving the data from another user.

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?

Monitor google search in Java

for my master thesis I need to keep track of google searches that the users perform. It should be a web project. At first I want to setup a server (that acts like a proxy) to monitor all actions (search queries) performed by the user.
The server should deliver the google search page. I need to keep track of the input the users make and the corresponding results returned from google as well.
My questen is now.. How should I start?
I am not really sure which webserver to use. Should I use tomcat / jetty / or something else?
What about Java Server Faces or Servlets? I worked with JSF long time ago but I am not sure whether its a good decision to use it.
The server should deliver the google search page. Here is my idea: The user connects to my server. The server "reads" the google page and returns it (the source code) to the user. I think of using a listener on the default search field to monitor the search queries of the users. But how is it possible to monitor the results returned from google? The google site itself uses JavaScript I guess. So when the user makes some input it is directly sent to google and the results are directly shown on the webpage thus my webserver does not see anything from the connection between the client and the google services.
The main idea is to monitor a search query and the corresponding search results.
I just need some help and ideas to get started. This is just a small part of my thesis. I do not want to start from zero during my editing time thus I want to make sure that I make the right choices before I start.
Thank you in advance... best regards.
You could use netty as a proxy and just filter and log all search queries. But then again why even use java? From what you describe you wan't to play man-in-the-middle and manipulate/log http traffic.
A quick google search came up with this for python: https://code.google.com/p/proxpy/
Edit: and similar in java https://github.com/adamfisk/LittleProxy

Updating webpage info from socket (JSP)

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

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".

Categories