2016-09-20 8 views
0

私はログインWebページを作成しましたサイトにログインするには ログインしようとすると、何も反応しませんが、sign'inボタンをクリックすると、電子メールまたはパスワードが間違っている(私はこのコードを自分のサーブレットに挿入しました)というメッセージが表示されます。フィールドは空ですが、このプロセスの後に再度資格情報を入力するとログインできるようになります。ログインフォームにログインできません

私は最初に、サーブレットが電子メールまたはパスワードを間違えるようにするよりも、サインインボタンをクリックする必要があります。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 
    pageEncoding="ISO-8859-1"%> 
 
<!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=ISO-8859-1"> 
 
<title>iCliniX</title> 
 
<%@ include file="controls/css.jsp" %> 
 
<%@ include file="controls/js.jsp" %> 
 
</head> 
 
<body> 
 

 

 

 
<div class="account-container login"> 
 
\t 
 
\t <div class="content clearfix"> 
 
\t \t 
 
\t \t <form action="../AdminLoginServlet" method="post"> 
 
\t \t 
 
\t \t \t <h1>Sign In</h1> \t \t 
 
\t \t \t 
 
\t \t \t <div class="login-fields"> 
 
\t \t \t \t 
 
\t \t \t \t <p>Sign in using your registered account:</p> 
 
\t \t \t \t 
 
\t \t \t \t <div class="field"> 
 
\t \t \t \t \t <label for="username">Username:</label> 
 
\t \t \t \t \t <input type="text" id="username" name="username" value="" placeholder="Username" class="login username-field" /> 
 
\t \t \t \t </div> <!-- /field --> 
 
\t \t \t \t 
 
\t \t \t \t <div class="field"> 
 
\t \t \t \t \t <label for="password">Password:</label> 
 
\t \t \t \t \t <input type="password" id="password" name="password" value="" placeholder="Password" class="login password-field"/> 
 
\t \t \t \t </div> <!-- /password --> 
 
\t \t \t \t 
 
\t \t \t </div> <!-- /login-fields --> 
 
\t \t \t 
 
\t \t \t <div class="login-actions"> 
 
\t \t \t \t 
 
\t \t \t \t <span class="login-checkbox"> 
 
\t \t \t \t \t <% 
 
\t \t \t \t \t \t String value = (String)request.getSession().getAttribute("registration"); 
 
\t \t \t \t \t \t if(value!=null){ 
 
\t \t \t \t \t \t \t out.print(value); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t %> 
 
\t \t \t \t </span> 
 
\t \t \t \t \t \t \t \t \t 
 
\t \t \t \t <input type="submit" class="button btn btn-secondary btn-large" value="Sign In" /> 
 
\t \t \t \t 
 
\t \t \t </div> <!-- .actions --> 
 
\t \t \t 
 
\t \t \t 
 
\t \t </form> 
 
\t \t 
 
\t </div> <!-- /content --> 
 
\t 
 
</div> <!-- /account-container --> 
 

 
<!-- Text Under Box --> 
 
<div class="login-extra"> 
 
\t <a href="forgotpassword.jsp">Forgot Password</a> 
 
</div> <!-- /login-extra --> 
 

 

 

 
</body> 
 

 
</html>

ServeltスクリプトJSPファイルのログインの

JSPコード。 AdminLoginServelt.java

package com.iclinix.controller; 
 

 
import java.io.IOException; 
 
import java.sql.Connection; 
 
import java.sql.DriverManager; 
 
import java.sql.ResultSet; 
 
import java.sql.Statement; 
 

 
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 javax.servlet.http.HttpSession; 
 

 

 
@WebServlet("/AdminLoginServlet") 
 
public class AdminLoginServlet extends HttpServlet { 
 
\t private static final long serialVersionUID = 1L; 
 
     
 
    
 
\t protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
 
\t \t 
 
\t } 
 

 
\t 
 
\t protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
 
\t \t String email = request.getParameter("username"); 
 
\t \t String pass = request.getParameter("password"); 
 
\t \t HttpSession s = request.getSession(); 
 
\t \t try { 
 
\t \t \t Class.forName("com.mysql.jdbc.Driver"); 
 
\t \t \t Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/iclinix","root","root"); 
 
\t \t \t Statement st = con.createStatement(); 
 
\t \t \t String mail = null, password = null; 
 
\t \t \t ResultSet rs = st.executeQuery("select * from tbl_admin_details where email='"+email+"'"); 
 
\t \t \t while(rs.next()){ 
 
\t \t \t \t mail = rs.getString("email"); 
 
\t \t \t \t password = rs.getString("password"); 
 
\t \t \t } 
 
\t \t \t if(mail!=null && password!=null &&email.equals(mail)&&pass.equals(password)){ 
 
\t \t \t \t response.sendRedirect("cpaneliclinix/index.jsp"); 
 
\t \t \t } 
 
\t \t \t else{ 
 
\t \t \t \t s.setAttribute("registration", "Email Or Password are Wrong!!!"); 
 
\t \t \t \t response.sendRedirect("cpaneliclinix/login.jsp"); 
 
\t \t \t } 
 
\t \t } catch (Exception e) { 
 

 
\t \t } 
 
\t } 
 

 
}

私はあなたが私の質問を得たいと考えています。

答えて

0

変化として下記のフォームアクション、../AdminLoginServletはサーブレットで、また

<form action="AdminLoginServlet" method="post"> 

無効なURLであるためには、のsendRedirect内のURLに関連した以下の変更を行います。

response.sendRedirect("index.jsp");//cpaneliclinix/index.jsp replaced 
response.sendRedirect("login.jsp");//cpaneliclinix/login.jsp replaced 

あなたのルートコンテキストの場所にindex.jspを& login.jspをファイルがあることを確認してください。私はeclipseを使用している場合はWebContentフォルダにあります。

関連する問題