Pass Java Database results to JavaScript/PHP mobile websites - java

We're trying to make a mobile website that will be coded in JavaScript / PHP. We have a database that is queried and the results are retrieved using java code. How do I pass the results from my java code to the mobile website?
edit -
the java connects to the database, queries the results, forms lists and passes it to the php/javascript code, that will display it in the website. There's no actual processing required in the PHP code. It's more like a bunch of functions in java do the work, while calling PHP modules to display the result in a webpage.

When you say Java, you mean something like WebLogic or TomCat servers? I guess it's not the case. I guess you can host your Java code in one of those servers and create webservices, that will serve data to your frontend PHP servers.
See http://en.wikipedia.org/wiki/Service-oriented_architecture for the general idea.

Related

How do you get data from a server via Ruby and then pass this data into Java/Android classes?

I am making a simple todo list Android application using Ruby (Specifically ActiveRecord) to get data from a database containing Users (made up of attributes like name, emails, todo lists etc). My problem is I want to pass the User data from the Ruby to the Java/Android code (for example to load all a users information after login).
Similarly, how would I pass data from the Java/Android code back to ruby, so that it may update a users information on the database when necessary?
Please keep in mind that I MUST use ruby.
The basic idea is to get data by hitting URL on web from your mobile Android app:
You need to just create web services in Ruby that will return you data in the different formats like JSON, HTML, YAML, XML from which you can parse it on your mobile app. Usually we prefer JSON/XML formats data that will be easy to parse on mobile site.
Here you go, for creating RESTful api in Rails there are many tutorials and example are available on web like below:
Tutorials or screencasts on building a REST web service on Rails
http://pivotallabs.com/building-a-fast-lightweight-rest-service-with-rails-3/
http://railscasts.com/episodes/350-rest-api-versioning
http://gavinmorrice.com/blog/posts/21-building-a-rest-api-in-rails-3
http://codedecoder.wordpress.com/2013/02/21/sample-rest-api-example-in-rails/
http://jes.al/2013/10/architecting-restful-rails-4-api/
Ruby will go as far as serving the data to your android application. In order for your android application to be able to 'understand' the data it receives, both the server and your android application need to agree on an exchange format, in which the data is to be encoded: json, xml, yaml, or even a more sophisticated serialization framework like protobuf, if there is a compelling need to go there.
You might want to start by looking up those.

How to access online mysql database in android?

I have created an online database about the restaurants and I need to access this database through my android application, so that I can display the data to the users after filtering. My application does not need to update the database, but my problem is how to connect to my online mysql database and provide it to the users? I have looked on many suggestions on this site as well as on others, and I just found I have to use JSON parser while accessing but do not how to do it.
The best solution is provide a public API, managed for example with PHP, which delivers your database data filtered and displayed as your Android application needs.
This link might help you . http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
Just get an understanding of JSON parsers and how it can be used in android for retrieving data from database on server... you can write webservices in php..
You need to provide a server side solution that the Android application can speak to. PHP scripts are a good way to go, that can directly interface with the MySQL database, and return results to the device.
You can then be creative with the PHP script, by sorting the results etc, and providing a more comprehensive solution by taking away some of the processing from the Android device, and doing it server side where battery life isn't as much of a problem.
You simply need to implement web service calls on the Android device, simple GET/POST requests over HTTP suffice depending on what you intend to do. Have a look into REST APIs for guidelines on how to implement properly.
You can easily add a PHP script to the same server as the MySQL database for this

Getting Data from java Applet using PHP Zend Framework Webservice

I have to make a web-service in Zend Framework for getting data from java applet.
Basically its a game built using Java Applet. I want to store result in my website's mysql database.
So I am trying to make a web service using Zend_Rest_server which will be accessed by Java applet code and I will get result data through web-service and will store them in MySql database.
Let me know if my concept is wrong. OR if I can do same task in another easier way.
I gone through some online tutorial for Zend_Rest_Sever but all are basic.
I made simple server for getting a variable value. But its not working in java application saying "Path not fond" Might be due to zend framework routing url.
Thanks in advance
Have you set the Zend_Rest_Route(s) needed?
You might want to check this out: http://mwop.net/blog/228-Building-RESTful-Services-with-Zend-Framework

Remotely calling Java from php

I have a java program that runs on a couple different computers and I want to be able to be able to access them remotely. I don't need to do anything crazy, just some very basic input output (get and set type stuff). I could write a client type application and set each program to a server with RMI and do it that way but I will not always be on the same computer and do not want to have to carry the .java file around with me.
I'd prefer to write a simple php webpage that I can access from anywhere and have some very basic buttons that could send the commands to the different Applications and receive back some output.
Problems is that it would probably impossible to get my host to load anything other then php onto the server where I'd host my webpage.
Does anyone have any ideas? I've tried googling it and found a couple things out there that sort of sound like what I need but the more I look into them they seem to not be what I wanted after all.
If you really want to do this right I'd suggest looking at a Java web framework (I use Play! myself) to create a RESTful web service and then sending requests from your PHP code that will fetch JSON data.
A framework like Play will make it very easy to get a REST web service running. Just create some wrappers that invoke your existing java code and call renderJSON to output the result.
From the PHP code you'll issue the request using curl and then read the response using json_decode which will turn it into a handy php variable.
This also has the advantage that either end can be changed without the other noticing, as long as the json data format is kept the same.
Based on the way you described your setup you'll probably run into routing issues trying to reach your Java apps from your PHP host. I'd recommend you try something else: have your Java apps frequently check with your PHP app if there are any updates. You can simply use a Java URL connection and a timer:
http://download.oracle.com/javase/6/docs/api/java/util/Timer.html
http://download.oracle.com/javase/6/docs/api/java/net/URL.html

Sending HTML Form Data to Java

I have a Java program that I'm trying to interact with over the web.
I need to gather form data from the user on a Drupal site that I don't have any control over, send it to the Java program, and send the output back to the user. The Java program needs to load a lot of libraries every time it's run, so it needs to be up waiting for data from the user.
It'd be best for me to just have an HTML form for the input. What's the simplest way to deal with HTML form data using Java?
Also, I'm trying to call the Java program from a shell script. I want the program running in the background though so the libraries are loaded in advance. So ideally, I could use the server I set up for both applications.
Thanks for any help.
It sounds like you really just want to write a servlet (or use a higher level web framework, but a servlet would work fine). That makes it very easy to get web form data - you just ask for values by name, basically.
You could then "script" the application using curl, wget or something similar to make requests to the servlet.
Apologies if this doesn't answer your question - I'm finding it slightly tricky to understand exactly what you're trying to do, particularly as there are multiple layers of web UI involved, as far as I can see.
The easiest way to make POST requests with java is to use the Apache HttpClient or the more recent HttpComponents libraries.

Categories

Resources