Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过mysql使用jsp和servlet对web应用程序进行身份验证_Mysql_Jsp_Servlets_Login_Web - Fatal编程技术网

通过mysql使用jsp和servlet对web应用程序进行身份验证

通过mysql使用jsp和servlet对web应用程序进行身份验证,mysql,jsp,servlets,login,web,Mysql,Jsp,Servlets,Login,Web,我在一个web应用程序上工作,一直在使用身份验证代码,我已经在eclipse上使用hibernate完成了连接,现在我提交身份验证时,它是关于身份验证的。什么都没有发生,请帮助我,我是新手。 以下是JSP文件: <%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256"%> <!DOCTYPE html PUBLIC "-//

我在一个web应用程序上工作,一直在使用身份验证代码,我已经在eclipse上使用hibernate完成了连接,现在我提交身份验证时,它是关于身份验证的。什么都没有发生,请帮助我,我是新手。 以下是JSP文件:

    <%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Survey Project</title>
    <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" title="default" />
    <!--  jquery core -->
    <script src="js/jquery/jquery-1.4.1.min.js" type="text/javascript"></script>

    <!-- Custom jquery scripts -->
    <script src="js/jquery/custom_jquery.js" type="text/javascript"></script>

     <!-- MUST BE THE LAST SCRIPT IN <HEAD></HEAD></HEAD> png fix -->
     <script src="js/jquery/jquery.pngFix.pack.js" type="text/javascript"></script>
     <script type="text/javascript">
     $(document).ready(function(){
     $(document).pngFix( );
     });
     </script>
     </head>
     <body id="login-bg" >
     <!-- Start: login-holder -->
     <div id="login-holder">

 <!-- start logo -->
 <div id="logo-login"></div>
 <!-- end logo -->

 <div class="clear"></div>
 <form name="form1" method="post" action="../LoginServlet">
 <!--  start loginbox ................................................................................. -->
 <div id="loginbox">

 <!--  start login-inner -->
 <div id="login-inner">
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
        <th>Username</th>
        <td><input type="text"  class="login-inp" id="login" /></td>
    </tr>
    <tr>
        <th>Password</th>
        <td><input type="password" value=""  onfocus="this.value=''" class="login-inp" id="pass" /></td>
    </tr>
    <tr>
        <th></th>
        <td><input type="button" class="submit-login" id="submit" /></td>
    </tr>
    </table>
    </div>
    <!--  end login-inner -->
    <div class="clear"></div>
        </div>
  <!--  end loginbox -->
     </form>  
  <!--  start forgotbox ................................................................................... -->
<div id="forgotbox">
    <div id="forgotbox-text">Please send us your email and we'll reset your password.</div>
    <!--  start forgot-inner -->
    <div id="forgot-inner">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <th>Email address:</th>
        <td><input type="text" value=""   class="login-inp" /></td>
    </tr>
    <tr>
        <th> </th>
        <td><input type="button" class="submit-login"  /></td>
    </tr>
    </table>
    </div>
    <!--  end forgot-inner -->
    <div class="clear"></div>
    <a href="" class="back-login">Back to login</a>
</div>
<!--  end forgotbox -->

    </div>
   <!-- End: login-holder -->
   </body>
   </html>

}

是否有任何错误消息?您是否尝试过在servlet中放置断点或跟踪以查看发生了什么?(或者,如果它甚至被调用)+1,用于将数据库代码放在它所属的位置:在servlet中!
    package stage.servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.List;

    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 stage.Personnel;
    import stage.dao.HibernateSessionFactory;

    import net.sf.hibernate.HibernateException;
    import net.sf.hibernate.Query;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.Transaction;


    @WebServlet(name = "LoginServlet", urlPatterns = {"/LoginServlet"})
    public class LoginServlet extends HttpServlet {

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, HibernateException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {


            String login = request.getParameter("login");
            String pass = request.getParameter("pass");

            // creation d'un request dispatcher
            RequestDispatcher rd = null;

            Session s = HibernateSessionFactory.getSessionFactory().openSession();
            Transaction trs = s.beginTransaction();
            Query q = s.createQuery("from personnel where login='"+login+"'");

            List<Personnel> l = q.list();
            if(l.isEmpty())
            {
                 rd = request.getServletContext().getRequestDispatcher("/pages/echec1.jsp");

            }
            else{
                Personnel p = l.get(0);

                if(p.getPassword().equals(pass))
                {

                    request.setAttribute("operation", "affichage");
                    rd = request.getServletContext().getRequestDispatcher("/AdminServlet");


                }   


                else{


                rd = request.getServletContext().getRequestDispatcher("/pages/echec2.jsp");

                }



                rd.forward(request, response);



            }

        }

        finally {            
            out.close();
        }

 }

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (HibernateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (HibernateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>