我的数据库:CLICK HERE FOR IMAGE ::---database values
此处的验证码:-
import java.sql.*;
public class loginvalidate
{
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/conferencesystem","root","root");
PreparedStatement ps =con.prepareStatement
("select * from author where a_email=? and a_pwd=?");
ps.setString(1, email);
ps.setString(2, pass);
ResultSet rs =ps.executeQuery();
st = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return st;
}
}
[CLICK HERE FOR IMAGE ::--- Login page Image HERE
登录页面此处保留页面::-
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "Loginservlet")
public class Loginservlet 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(loginvalidate.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);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
}
}
[CLICK HERE FOR IMAGE ::--- AFTER ENTERING DETAILS AT LOGIN PAGE
a_email和a_pwd字段没有例外,请帮助我成功验证探针,我在这里做错了什么,只是告诉我,我不知道如何执行此操作,但是以某种方式我得到了用于验证登录名的代码该页面不起作用,我认为我在这里遗漏了一些东西,而我目前正在学习Servlet。谢谢...
答案 0 :(得分:0)
是的,我明白了!,
正确的密码是:-
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/conferencesystem", "root", "root");
PreparedStatement pst = conn.prepareStatement("Select a_email,a_pwd from author where a_email=? and a_pwd= ? ");
pst.setString(1, email);
pst.setString(2, pass);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
out.println("<html>");
out.println("<head></head>");
out.println("<body>");
out.println("<h1>Correct login credentials</h1>");
out.println("</body>");
out.println("</html>");
}
else {
out.println("Incorrect login credentials");
}
}