如何在用户登录时验证某个电子邮件和密码?验证电子邮件地址和密码
protected void doPost(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException {
String email=request.getParameter("email");
String pass=request.getParameter("pass");
OutputStream out = res.getOutputStream();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8080/college", "root", "root");
Statement st=con.createStatement();
String strSQL = "SELECT email,password FROM student";
如何在SELECT语句后继续?我宁愿使用if...else
声明来进行验证。
我想你应该首先解释你的意思是“验证”。这也会帮助你思考这个问题。 –
我认为这是更好地创建连接和初始化的OutputStream – Slimu
我们不知道你的数据库结构,但为什么不'SELECT COUNT(*)FROM学生WHERE电子邮件=前做验证? AND密码=?'。使用['PreparedStatement'](http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html)。并且**不要在数据库中以明文存储密码**。 –