簡體   English   中英

從tomcat服務器中的war文件運行Java類

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

我已經在遠程tomcat服務器中上傳了一個war文件。在這里我必須解壓縮war文件。在這里我必須在瀏覽器中運行Demo java類。我該怎么辦?

這是Demo.java的保存路徑:

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

在這里,我必須運行以下方法:URL http://xx.xx.xx.xxx:8080/Example/意味着正在成功獲取這些頁面。請檢查以下內容: http : //screencast.com/t/DKZW1t9Z1

這是我的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;
    }
    }

如何在瀏覽器上運行Demo.java類,請幫助我。

那是因為您需要編寫一個運行代碼的servlet。 基本上,當您向上述給定鏈接發出請求時,它將調用Demo.java類並給出輸出。

建議您首先學習有關servlet的一些基礎知識。 那應該有幫助。

所以有一個像

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