找不到符号

时间:2016-04-01 03:50:59

标签: java web-applications compiler-errors package symbol-not-found

DBHelper.java

package com.control;    
import java.sql.*;    
public class DBHelper 
{
Connection conn;
Statement st;
ResultSet rs;
public DBHelper()throws ClassNotFoundException
{
    Class.forName("oracle.jdbc.driver.OracleDriver");
}

public boolean getConnection()throws SQLException
{
    conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
    if(conn!=null)
        return true;
    return false;
}

public void execute(String query)throws SQLException
{
    st=conn.createStatement();
    st.execute(query);

}
public boolean match(String uname,String pwd)throws Exception
{
    st=conn.createStatement();
    rs=st.executeQuery("select * from register");


        while(rs.next())
        {
            String unm=rs.getString(1);
            String pd=rs.getString(2);
            if(uname.equals(unm) && pwd.equals(pd))
            {
                return true;
            }

        }
        return false;


}



}

LoginSevlet.java

package com.control;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class LoginServlet extends HttpServlet
{


    public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
    {
        try{
        DBHelper obj=new DBHelper();
        obj.getConnection();
        PrintWriter out=res.getWriter();
        res.setContentType("text/html");
        String uname=req.getParameter("email");
        String pwd=req.getParameter("password");
        //ResultSet rs=obj.match(uname,pwd);
        //if(uname.equals(rs.getString(1)) && pwd.equals(rs.getString(2)))
        if(obj.match(uname,pwd))
        {
            RequestDispatcher rd=req.getRequestDispatcher("profile.html");
            rd.forward(req,res);

        }
        else
        {

            RequestDispatcher rd=req.getRequestDispatcher("index.html");
            rd.include(req,res);
            out.println("<b>Incorrect Email or password!</b>");
        }

        }catch(Exception e)
        {

        }

    }    
}
  

我正在尝试访问LoginServlet中的DBHelper类,而编译我做了 javac DBHelper.java   javac -cp“C:\ Users \ dell \ Desktop \ MYServlet \ WEB-INF \ lib \ servlet-api-2.5.jar;” LoginServlet.java   LoginServlet.java:13:错误:找不到符号
                         DBHelper obj = new DBHelper();
                         ^
   符号:类DBHelper
   location:class LoginServlet
  LoginServlet.java:13:错误:找不到符号
                 DBHelper obj = new DBHelper();
                                          ^
   符号:类DBHelper
   location:class LoginServlet
  2错误
  我已将.java文件放在C:\ Users \ dell \ Desktop \ MYServlet \ WEB-INF \ classes \ com \ control中   所有的文件都在同一个包中,而且太公开了,为什么LoginServlet无法访问DBHelper类

1 个答案:

答案 0 :(得分:0)

因为您的班级import com.control.*;中没有LoginServlet。 有关包Java packages的更多信息 并且请在使用包时尝试使用正确的命令进行编译和执行。