How does this Java application change when deployed on a server?
I want to write a Java application that talks to a MySQL database on a server and changes the value of some variable v based on what it finds in the database.
If I were to simply do this on my computer I would have something like:
//import database stuff
public class Test{
int v;
public Test()
{
v=0;
}
public void main (String[]args){
Test t = new Test();
t.setVariable();
}
public void setVariable(){
// connect to database etc etc
if(something in MySQL database is true){
v= 10;
}
else{
v=30;
}
}
}
Now lets say I wanted to deploy this on a web server and expose the variable v to multiple users on the web who want to access a home.php file that was something like
$v = //call java program to return v
echo $v;
1) what would change in my java code or how I think of the whole problem? do i need a servlet? or tomcat? or do i just need to install the jdk?
2) how about the call from the home.php file h开发者_Python百科ow is it made?
what is a good resource I can use to learn about these issues?
Thanks alot!
i would code this using ajax language. I would write a servlet which would be called from the web page (javascript). In the servlet i would write a DAO layer which will talk to the MySQL database. In the servlet, the business logic (i.e. checking the value) would be written & appropriate value would be returned back to the front end (web page).
精彩评论