我正在使用Apache TomCat Server在eclips中运行一个WEB服务程序。我正在手动运行它。在此期间它会给我一个无法找到符号LoginResource.class的错误。
我有两个文件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 :(得分:0)
问题原因:类文件必须放在eclipse .metadata目录中,而不是放在tomcat webapp目录中(这取决于你使用的是哪个eclipse插件)
解决方案:在tomcat中部署应用程序(war文件),现在您应该能够无错误地启动应用程序