JSP、Java、データベース。ログインしようとしたときに間違ったデータが送信された場合、同じindex.jspをもう一度呼び出すにはどうすればよいですか?

user1282256

データベースに接続できますが、ログインしようとしたときに誤ったデータが渡された場合、同じindex.jspファイルを再度呼び出すことができません。

データベースに接続すると、index.jspファイルが表示され、次のデータを含む電子メールとパスワードを入力します:[email protected]。これらのデータはデータベースにあるため、menu.jspページにリダイレクトされます。間違ったデータを入力しました:[email protected] 12それはまた私をmenu.jspにリダイレクトします。今私はこのエラーを受け取ります:


Mar 30, 2014 12:14:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Cap] threw exception [/index.jsp     
(line: 33, column: 41) quote symbol expected] with root cause
org.apache.jasper.JasperException: /index.jsp (line: 33, column: 41) quote symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
    ..........

index.jspの33行目は

 <jsp:getProperty name="login" property="value" />

getEmailとgetPaswordはnullを返さず、期待どおりに適切な値のみを返します。


    <jsp:useBean id="member" class="StaffMember" scope="session"/>
    <jsp:setProperty name="member" property="*"/>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <title>Welcome</title>
    </head>
    <body bgcolor="lightblue">
    <font size=4>

    <center>
    </center>
    <form method=post> <hr><br>
    <center>
    <b>LOGIN</b><p>
    <input type=text name=email value= email value = member.setEmail(email)> <p>
    <input type=text name=password value=password value = member.setPassword(password)> <p>
    <input type=submit value="Submit">
    <jsp:getProperty name="login" property="value" />
 <c:if value = "false" action="index.jsp"></c:if>
 <c:if value = "true" action="menu.jsp"></c:if>
    </center>
    <img src="<%=request.getContextPath()%>/images/ndnuLogo.jpg"/>
    <br><hr>
    </form>
    </font>  
    </body>
    </html>


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

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.view.Viewable;

    public class LoginServiceImplem implements LoginService{
    private Connection connection;
    private Statement statement;
    private boolean value; //used to check if user that login is on the list of user available to 
                          //test

    public LoginServiceImplem() throws SQLException{
            connection = null;
            statement = null;
        value = false;
        StaffMember sm = new StaffMember();
        value = login(sm.getEmail(), sm.getPassword());
    }

    public boolean getValue() {
    return value;
    }

public void setValue(boolean value) {
        this.value = value;
    }

public boolean login(String email, String password) throws SQLException{
        System.out.println(email + " " + password);
        String query = "SELECT * FROM cap.member WHERE Email= '" + email + "'"
                + " AND Password = '" + password + "'";
        ResultSet rs = null;
        try {
            try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
            //builds a connection and statement
            connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/" + 
            "cap", "root", "");
            System.out.println("After connection");
            statement = connection.createStatement(); 
            System.out.println("After statement");
            rs = statement.executeQuery(query);
            System.out.println("After rs");
            //if the statement returns something
            if(rs.next()){
                //and email and password match the database information, return true
                return(email.equals(rs.getString("Email")) 
                        && password.equals(rs.getString("Password")));
            }
        }finally {
            //close all connections
            DbUtil.close(rs);
            DbUtil.close(statement);
            DbUtil.close(connection);
        }return false;
    }
}


public class StaffMember {

    private String emailAddress;
    private String password;

    public StaffMember() {  
        emailAddress = "[email protected]";
        password = "1234";  
    }

    /* The setEmail method sets the employee's email */
    public void setEmail(String email) {
    emailAddress = email;
    }

    public void setPassword(String pword){
        password = pword;
    }

    /* The getEmail method gets the employee's email. */
    public String getEmail() {
        return emailAddress;
    }    

    public String getPassword(){
        return password;
    }
}

ここに画像の説明を入力してください

ポール

何も見逃していない場合は、Javaコードに以下の行がないため、「適切なドライバーが見つかりません」というエラーが発生すると思います。何か足りないものがあれば教えてください。

 Class.forName("com.mysql.jdbc.Driver");

これを「LoginServiceImplem」クラスに追加できます。静的ブロックでは次のようなもの

static {
    Class.forName("com.mysql.jdbc.Driver");
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ