Jump to content

Hey, so I've got an issue I can't seem to solve or find a way around and would love any help anyone can give.

 

I have a Java Servlet that contains a database connection and gathers values from the database into an Array. I'm just wondering how to get this array back to php so I can populate a HTML table with the data. I realise that I can just get the database in the php page and easily do it there, but the requirements say the Servlet has to do the data collection.

 

The values are Float and a basic database/table structure would look like this.

[table][tr]	[th]ID[/th]	[th]Time Stamp[/th]	[th]Value[/th][/tr][tr]	[td]1 (Int)[/td]	[td](randomTime) (BigInt)[/td]	[td](Value) (Float)[/td][/tr][/table] 
Desktop Build
Spoiler
CPU: Intel Core i7-4770k
CPU Cooler: CoolerMaster Hyper 212X
Motherboard: ASUS Maximus VI Hero
RAM: Corsair Vengeance Pro 1866MHz - 16GB
GPU: ASUS GeForce GTX 780 - 3GB, MSI GeForce GTX 780 - 3GB
Storage: Samsung 840 Pro - 128GB, Western Digital Blue - 1TB, Seagate Barracuda - 1TB, Seagate Barracuda - 3TB
PSU: Silverstone Strider Plus 750W
Display(s): Dell Ultrasharp 27" (2560 x 1440)
Keyboard: Razer BlackWidow Ultimate 2014
Mouse: Logitech G502
Operating System: Windows 8.1
 
 
Laptop
Spoiler
Current
CPU: Intel Core i7-4710HQ
RAM: 16GB
GPU: Nvidia GTX 970M
Storage: Samsung 840 EVO - 250GB, Hitachi Travelstar 7K1000 - 1TB
Display(s): 15.6" IPS Display (1920 x 1080)
Mouse: Logitech G502
Operating System: Windows 8.1
 
Old - Given away
CPU: Intel Core i7 2630QM
RAM: 6GB
GPU: Nvidia GT 540M
Storage: Samsung 840 Pro - 128GB, Toshiba - 750GB
Display(s): 15.6" Display (1366 x 768)
Mouse: Logitech G502
Operating System: Windows 7
 
 
 
 
Other (Audio & Devices)
Spoiler
Speakers: Creative Gigaworks T40 Series II
Headphones: Sennheiser Momentum - Over-Ear
Bluetooth Speaker: Logitech UE Boom, Logitech UE Boom 2
Tablet: iPad 4th Gen
Phone: LG G4
 
Phone Accessories:
3 Spare Batteries
1 Battery Pack (10000 mAh)
IEMs: Can't Remember....
 
Retired Devices:
Samsung S4 (Broke... Half Fixed, Given away)
NDS (Traded in)
iPod Touch 2nd Gen (Traded in)
iPod Touch 4th Gen (Damaged Power Connector)
Link to comment
https://linustechtips.com/topic/372048-float-array-from-java-to-htmlphp/
Share on other sites

Link to post
Share on other sites

Yeah... Gonna need a lot more information about this entire thing.

 

Why are you getting DB info from Java, and passing it to PHP?

 

Need example code.

 

Ok here's a bit more to go off.

It's a project and the requirement is to have a Java Servlet that does all the database related stuff and then pass back what you need. So I have a .php webpage that meta refreshes every 10 seconds, which is when I want it to keep updating a html table on the .php webpage as new data is added to the database in the background.

 

Here's the Java Servlet's code to get the data from the database (without connection details):

res3 = st.executeQuery("SELECT * FROM sensorData WHERE `sensorID` = '3'");while (res3.next()) {    lightDataArray.add((float) res3.getInt("sensorID"));    lightDataArray.add((float) res3.getLong("timeStamp"));    lightDataArray.add(res3.getFloat("recordedValue"));    if (res3.isLast()) {        currentLightValue = res3.getFloat("recordedValue");    }}
Desktop Build
Spoiler
CPU: Intel Core i7-4770k
CPU Cooler: CoolerMaster Hyper 212X
Motherboard: ASUS Maximus VI Hero
RAM: Corsair Vengeance Pro 1866MHz - 16GB
GPU: ASUS GeForce GTX 780 - 3GB, MSI GeForce GTX 780 - 3GB
Storage: Samsung 840 Pro - 128GB, Western Digital Blue - 1TB, Seagate Barracuda - 1TB, Seagate Barracuda - 3TB
PSU: Silverstone Strider Plus 750W
Display(s): Dell Ultrasharp 27" (2560 x 1440)
Keyboard: Razer BlackWidow Ultimate 2014
Mouse: Logitech G502
Operating System: Windows 8.1
 
 
Laptop
Spoiler
Current
CPU: Intel Core i7-4710HQ
RAM: 16GB
GPU: Nvidia GTX 970M
Storage: Samsung 840 EVO - 250GB, Hitachi Travelstar 7K1000 - 1TB
Display(s): 15.6" IPS Display (1920 x 1080)
Mouse: Logitech G502
Operating System: Windows 8.1
 
Old - Given away
CPU: Intel Core i7 2630QM
RAM: 6GB
GPU: Nvidia GT 540M
Storage: Samsung 840 Pro - 128GB, Toshiba - 750GB
Display(s): 15.6" Display (1366 x 768)
Mouse: Logitech G502
Operating System: Windows 7
 
 
 
 
Other (Audio & Devices)
Spoiler
Speakers: Creative Gigaworks T40 Series II
Headphones: Sennheiser Momentum - Over-Ear
Bluetooth Speaker: Logitech UE Boom, Logitech UE Boom 2
Tablet: iPad 4th Gen
Phone: LG G4
 
Phone Accessories:
3 Spare Batteries
1 Battery Pack (10000 mAh)
IEMs: Can't Remember....
 
Retired Devices:
Samsung S4 (Broke... Half Fixed, Given away)
NDS (Traded in)
iPod Touch 2nd Gen (Traded in)
iPod Touch 4th Gen (Damaged Power Connector)
Link to post
Share on other sites

 

Ok here's a bit more to go off.

It's a project and the requirement is to have a Java Servlet that does all the database related stuff and then pass back what you need. So I have a .php webpage that meta refreshes every 10 seconds, which is when I want it to keep updating a html table on the .php webpage as new data is added to the database in the background.

 

Here's the Java Servlet's code to get the data from the database (without connection details):

res3 = st.executeQuery("SELECT * FROM sensorData WHERE `sensorID` = '3'");while (res3.next()) {    lightDataArray.add((float) res3.getInt("sensorID"));    lightDataArray.add((float) res3.getLong("timeStamp"));    lightDataArray.add(res3.getFloat("recordedValue"));    if (res3.isLast()) {        currentLightValue = res3.getFloat("recordedValue");    }}

 

So make your java code write out the data array as a json object, have your PHP one read it in and prase it into an array/object with json_decode, and then you have the data.

--Neil Hanlon

Operations Engineer

Link to post
Share on other sites

So make your java code write out the data array as a json object, have your PHP one read it in and prase it into an array/object with json_decode, and then you have the data.

 

Well I have tried to get that working, but it never seems to actually work properly. Could you give me a little bit of example code on the java and php side to work off?

Desktop Build
Spoiler
CPU: Intel Core i7-4770k
CPU Cooler: CoolerMaster Hyper 212X
Motherboard: ASUS Maximus VI Hero
RAM: Corsair Vengeance Pro 1866MHz - 16GB
GPU: ASUS GeForce GTX 780 - 3GB, MSI GeForce GTX 780 - 3GB
Storage: Samsung 840 Pro - 128GB, Western Digital Blue - 1TB, Seagate Barracuda - 1TB, Seagate Barracuda - 3TB
PSU: Silverstone Strider Plus 750W
Display(s): Dell Ultrasharp 27" (2560 x 1440)
Keyboard: Razer BlackWidow Ultimate 2014
Mouse: Logitech G502
Operating System: Windows 8.1
 
 
Laptop
Spoiler
Current
CPU: Intel Core i7-4710HQ
RAM: 16GB
GPU: Nvidia GTX 970M
Storage: Samsung 840 EVO - 250GB, Hitachi Travelstar 7K1000 - 1TB
Display(s): 15.6" IPS Display (1920 x 1080)
Mouse: Logitech G502
Operating System: Windows 8.1
 
Old - Given away
CPU: Intel Core i7 2630QM
RAM: 6GB
GPU: Nvidia GT 540M
Storage: Samsung 840 Pro - 128GB, Toshiba - 750GB
Display(s): 15.6" Display (1366 x 768)
Mouse: Logitech G502
Operating System: Windows 7
 
 
 
 
Other (Audio & Devices)
Spoiler
Speakers: Creative Gigaworks T40 Series II
Headphones: Sennheiser Momentum - Over-Ear
Bluetooth Speaker: Logitech UE Boom, Logitech UE Boom 2
Tablet: iPad 4th Gen
Phone: LG G4
 
Phone Accessories:
3 Spare Batteries
1 Battery Pack (10000 mAh)
IEMs: Can't Remember....
 
Retired Devices:
Samsung S4 (Broke... Half Fixed, Given away)
NDS (Traded in)
iPod Touch 2nd Gen (Traded in)
iPod Touch 4th Gen (Damaged Power Connector)
Link to post
Share on other sites

Not sure if you have done this already or not. I have never worked with jsp stuff before, but can't you make the jsp page print the result from the database when it is called?

 

Basically I am thinking that you could do something like this in php

$result = file_get_contents('localhost/javaservlet.jsp');

Not sure if that would work or not. Just a thought. And like Neil said you can just make it return a JSON object.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×