Reputation: 63
Hi I am trying to get a login information through the JSP's. I got an error Can't find symbol : Login
while compiling LoginServlet.java
Here is my code, can you please tell the solution of that problem?
Login.java
public class Login
{
public static boolean validate(String name, String pass)
{
boolean status = false;
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String driver = "oracle.jdbc.driver.OracleDriver";
String userName = "system";
String password = "dad";
try
{
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url,userName, password);
pst = conn.prepareStatement("select * from login where user=? and password=?");
pst.setString(1, name);
pst.setString(2, pass);
rs = pst.executeQuery();
status = rs.next();
}
catch (Exception e)
{
System.out.println(e);
}
finally
{
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pst != null) {
try {
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return status;
}
}
LoginServlet.java
public class LoginServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void do Post(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("username");
String p=request.getParameter("userpass");
HttpSession session = request.getSession(false);
if(session!=null)
session.setAttribute("name", n);
session.setAttribute("pass", p);
if(Login.validate(n,p))
{
Request Dispatcher rd=request.getRequestDispatcher("welcome.jsp");
rd.forward(request,response);
}
else
{
out.print("<p style=\"color:red\">Sorry username or password error</p>");
Request Dispatcher rd=request.getRequestDispatcher("index.jsp");
rd.include(request,response);
}
out.close();
}
}
Upvotes: 0
Views: 1593
Reputation: 141
import the Login class in to the LoginServlet.java . If both are in same package then you have to add it into class path.
it may be helpful for you. thanks
Upvotes: 1
Reputation: 15333
You need to import you Login
class in your Servlet.
It might be due to your Login
class and LoginServlet
both are in different packages. So you need to import Login
class in your LoginServlet
, before using it.
You need to add something like,
import yourpackage.Login;
in the beginning of the LoginServlet
Upvotes: 1