当部署在服务器上时,这个 Java 应用程序会发生什么变化?
我想编写一个 Java 应用程序,它与服务器上的 MySQL 数据库进行通信,并根据在数据库中找到的内容更改某些变量 v 的值。
如果我只是在我的计算机上执行此操作,我会得到如下结果:
//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;
}
}
}
现在假设我想将其部署在 Web 服务器上,并将变量 v 公开给 Web 上想要访问 home.php 文件的多个用户像
$v = //调用java程序返回v
echo $v;
1)我的java代码会发生什么变化或者我如何看待整个问题?我需要一个servlet吗?还是雄猫?或者我只需要安装jdk?
2)来自 home.php 文件的调用是如何进行的?
我可以使用什么资源来了解这些问题?
多谢!
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 how is it made?
what is a good resource I can use to learn about these issues?
Thanks alot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用 ajax 语言对此进行编码。我会编写一个从网页(javascript)调用的servlet。在 servlet 中,我将编写一个 DAO 层,它将与 MySQL 数据库通信。在 servlet 中,将编写业务逻辑(即检查值)。适当的值将返回到前端(网页)。
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).