2012-04-24 131 views
0

我使用Apache TomCat Server在eclips中运行WEB服务程序。我正在手动运行它。在此过程中,它会给我错误,找不到符号LoginResource.class。在Tomcat上手动运行Web服务

我有两个文件LoginResource.java和LoginApplication.java.Both文件被编译,但是当我在服务器上运行它它给了我那个错误。 当我直接在服务器上运行整个项目时,它会运行,但是当我手动运行服务器时会出现错误。

为了解决这个问题,我把两个文件(.class)放在同一个文件夹中,但是仍然有相同的错误。 任何人都可以解决这个问题。 以下是我的两个的.java文件 - LoginApplication ---->

package com.login; 

import org.restlet.Application; 
import org.restlet.Restlet; 
import org.restlet.routing.Router; 

public class LoginApplication extends Application { 

    public Restlet createInboundRoot() { 
    Router router = new Router(getContext()); 
    router.attach("/login", LoginResource.class); 

    return router; 
    } 
} 

LoginResource --->

package com.login; 

import org.json.JSONObject; 
//import org.restlet.data.CharacterSet; 
import org.restlet.data.Form; 
//import org.restlet.data.Language; 
//import org.restlet.data.MediaType; 
import org.restlet.data.Parameter; 
import org.restlet.representation.Representation; 
import org.restlet.representation.StringRepresentation; 
import org.restlet.resource.Get; 
import org.restlet.resource.ServerResource; 
import java.sql.*; 

public class LoginResource extends ServerResource { 

    String name = "Login Example"; 


    public String getName() 
    { 
     return name; 
    } 


    protected Representation put(Representation input) { 

     //Representation r = null; 
     JSONObject jsonResult = new JSONObject(); 

     Connection con = null; 
     String dbUrl = "jdbc:mysql://localhost:3306/loginDb"; 
     String driver = "com.mysql.jdbc.Driver"; 

     //String result = "Login Failed ..."; 

     try { 

      Class.forName(driver).newInstance(); 
      con = DriverManager.getConnection(dbUrl, "loginDb", "loginDb"); 
      System.out.println("Connected to the database"); 

      Statement stm = con.createStatement(); 
      ResultSet rs = null; 

      String inputText = input.getText(); 
      System.out.println(inputText); 
      Form form = new Form(inputText); 

      String email = ""; 
      String password = ""; 
      for (Parameter entry : form) { 

       if(entry.getName().equals("email")) 
       { 
        email = entry.getValue(); 
       } 

       if(entry.getName().equals("password")) 
       { 
        password = entry.getValue();        
       } 
       System.out.println(entry.getName() + "=" + entry.getValue()); 
      } 

     if(email.equals("") || password.equals("")) 
     { 
      System.out.println("EmailId or Password not provided"); 
      jsonResult.put("success", false); 
      jsonResult.put("message", "EmailId or Password not provided"); 
     } 
     else 
     { 
      //rs = stm.executeQuery("select * from users where email = '" + email + "' and password = '" + password + "'"); 
      String query = "select * from users where email='" + email + "' and password='" + password + "'"; 
      rs = stm.executeQuery(query); 

      System.out.println("Query = " + query); 

      if(rs.next()) 
      { 
       query = "select * from users where email='" + email + "' and password='" + password + "' and verified = 1"; 
       ResultSet rs2 = stm.executeQuery(query); 

       if(rs2.next()) 
       { 
        System.out.println("Logged In successfully"); 
        jsonResult.put("success", true); 
        jsonResult.put("message", "Logged In successfully"); 
       } 
       else 
       { 
        System.out.println("Please confirm "); 
        jsonResult.put("success", false); 
        jsonResult.put("message", "Please confirm"); 
       } 
       rs2.close(); 
      } 
      else 
      { 
       System.out.println("In correct username or password"); 
       jsonResult.put("success", false); 
       jsonResult.put("message", "In correct username or password"); 
      } 

      /*r = new StringRepresentation(
        jsonResult.toString(), 
        MediaType.APPLICATION_JSON, 
        Language.ALL, 
        CharacterSet.UTF_8);*/ 

      rs.close(); 
     } 

     stm.close(); 
     con.close(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 


     System.out.println(jsonResult); 
     return new StringRepresentation(jsonResult.toString()); 
    } 

} 
+0

你是什么意思手动运行服务器?你也可以提供一些关于你在eclipse中使用什么插件的信息和一些异常的堆栈跟踪? – 2012-04-24 11:42:59

+0

手动是指从命令提示符运行服务器。在linux中我们必须手动运行服务器。关于stacktress只有错误是comming.I认为LoginApplication.class doesnot找到LoginResource.class文件。那就是为什么这个错误不能找到符号LoginResource.class。 – 2012-04-24 11:53:17

+0

你能否提一下在eclipse中使用哪个tomcat插件? – 2012-04-24 12:01:05

回答

0

问题的原因:类文件必须放置在eclipse目录.metadata而不是在tomcat webapp目录下(这取决于你使用的是哪个eclipse插件)

解决方案:部署你的应用程序(war f ile)在tomcat中,现在你应该能够无误地启动你的应用程序

+0

但是我的服务器上的应用程序,我的文件应该如何驻留在Eclips.It应该在Webapp文件夹,以便服务器可以访问它。 – 2012-04-24 13:17:27

相关问题