我使用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());
}
}
你是什麼意思手動運行服務器?你也可以提供一些關於你在eclipse中使用什麼插件的信息和一些異常的堆棧跟蹤? – 2012-04-24 11:42:59
手動是指從命令提示符運行服務器。在linux中我們必須手動運行服務器。關於stacktress只有錯誤是comming.I認爲LoginApplication.class doesnot找到LoginResource.class文件。那就是爲什麼這個錯誤不能找到符號LoginResource.class。 – 2012-04-24 11:53:17
你能否提一下在eclipse中使用哪個tomcat插件? – 2012-04-24 12:01:05