我已经在远程tomcat服务器上传了一个war文件。我必须解压war文件。我必须在我的browser上运行 Demo java类。我能做什么? ?
这是Demo.java的保存路径:
的/ var / lib中/ tomcat7 / web应用/实施例/ WEB-INF /类/ COM / testprops / WS
这里我必须运行这些意味着网址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类。请帮助我。
答案 0 :(得分:0)
那是因为你需要编写一个运行代码的servlet。基本上,当您向上面给定的链接发出请求时,它会调用Demo.java
类并给出输出。
建议首先学习一些关于servlet的基础知识。这应该会有所帮助。
所以有一个像
这样的简单servletpublic 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
}