======================== vaidate.java servlet =================== ===
import java.sql.*;
public class Validate
{
public static boolean checkUser(String email,String pass)
{
boolean st =false;
try{
//loading drivers for mysql
Class.forName("com.mysql.jdbc.Driver");
//creating connection with the database
Connection con=DriverManager.getConnection
("jdbc:mysql:/ /localhost:3306/test","root","studytonight");
PreparedStatement ps =con.prepareStatement
("select * from register where email=? and pass=?");
ps.setString(1, email);
ps.setString(2, pass);
ResultSet rs =ps.executeQuery();
st = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return st;
}
}
================== login.java servlet ======================== < / p>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Login extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String email = request.getParameter("email");
String pass = request.getParameter("pass");
if(**Validate**.checkUser(email, pass))
{
RequestDispatcher rs = request.getRequestDispatcher("Welcome");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("index.html");
rs.include(request, response);
}
}
=============================================== ==============
所以得到“错误:无法找到符号是显而易见的 if(Validate.checkUser(email,pass))
symbol:variable验证 location:class登录 1错误“
如何将该类名称用作变量pls建议.....