简体   繁体   English

从tomcat服务器中的war文件运行Java类

[英]run the java class from war file in tomcat server

i have uploaded one war file in remote tomcat server.here i have to unzip the war file.here i have to run the Demo java class on my browser.how can i do???? 我已经在远程tomcat服务器中上传了一个war文件。在这里我必须解压缩war文件。在这里我必须在浏览器中运行Demo java类。我该怎么办?

this is the saved path of Demo.java: 这是Demo.java的保存路径:

/var/lib/tomcat7/webapps/Example/WEB-INF/classes/com/testprops/ws / var / lib / tomcat7 / webapps / Example / WEB-INF / classes / com / testprops / ws

Here i have to run these means URL http://xx.xx.xx.xxx:8080/Example/ means am getting these page successfully.please check this: http://screencast.com/t/DKZW1t9Z1 在这里,我必须运行以下方法:URL http://xx.xx.xx.xxx:8080/Example/意味着正在成功获取这些页面。请检查以下内容: http : //screencast.com/t/DKZW1t9Z1

This is my Demo.java: 这是我的Demo.java:

 public class Demo {
 public String customerData(){
 String customerInfo = "";
 int a=10;
 customerInfo = customerInfo + a;
  try{
  Class.forName("com.mysql.jdbc.Driver");
   Connection con =  DriverManager.getConnection("jdbc:mysql://localhost:3306/android","androiduser","AN124@7#7");
  //Find customer information where the customer ID is maximum
   PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers");
   ResultSet result = statement.executeQuery();
   while(result.next()){
   customerInfo = customerInfo + a + "&" + result.getString("login") + "&" + result.getString("password") + "&"+result.getString("firstname") + "&"+result.getString("email");
   //Here "&"s are added to the return string. This is help to split the string in Android application
    }
      }
    catch(Exception exc){
    System.out.println(exc.getMessage());
     }  
    return customerInfo;
    }
    }

How can i run the Demo.java class on my browser.please help me. 如何在浏览器上运行Demo.java类,请帮助我。

That is because you need to write a servlet that runs the code. 那是因为您需要编写一个运行代码的servlet。 Basically when you give a request to the above given link, then it calls Demo.java class and the output is given. 基本上,当您向上述给定链接发出请求时,它将调用Demo.java类并给出输出。

It is recommended to please first learn a bit basics about servlets. 建议您首先学习有关servlet的一些基础知识。 That should help. 那应该有帮助。

So have a simple servlet like 所以有一个像

public void doGet(HttpServeletRequest r, HttpServletResponse s){
 Demo demo = new Demo();
 demo.run();//your Demo.java is invalid as all that try catch code needs to be inside a method
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM