Home>

Nice to meet you.
I am currently studying servlets.

Last question (https://www.tutorialfor.com/go.php?id=273094) Is a continuation of.

What I want to achieve this time

I want to use a redirect to transition from a servlet (Login.java) to another servlet (BookManagementListDisp.java) and display the message "Transition of BookManagementListDisp was successful."

Stumbling

How to transit from Login.java to BookManagementListDisp.java when login succeeds while reading a book.

response.sendRedirect("/BookManagementListDisp.java");

I tried to realize the description in Login.java, but the error shown in the picture comes out.

If i have any concerns, please let me know.

Thank you very much.

Source code
package exam;
import java.io.IOException;
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;
import dao.UserDAO;
@WebServlet("/Login")
public class Login extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {


        //Specify the character string encoding method received in the request
        request.setCharacterEncoding("UTF-8");
        LoggerTester lt = new LoggerTester();
        lt.outActionLog("Login", "Start processing");
        try {
            // Servlet initialization parameter information
            String loginid = request.getParameter("loginid");
            String userpassword = request.getParameter("userpassword");
            // Find user ID and password
            UserDAO dao = new UserDAO();
            UserDAO user = dao.selectUser(loginid, userpassword);
            //if (request.getParameter("username") == un){
            if (user != null) {
            HttpSession session = request.getSession(true);
            session.setAttribute("user", user);
            response.sendRedirect("/BookManagementListDisp.java");
            }else {
            request.setAttribute("loginErrorMessage","The input is incorrect.");
            getServletContext().getRequestDispatcher("/login.jsp").forward(request, response);

            }
// In case of DB error, register error message in request and forward to error screen
            }catch(Exception e){
                e.printStackTrace();
                request.setAttribute("dbConnectionError", "There was an error with the database connection.");
                getServletContext().getRequestDispatcher("/errorMessage.jsp").forward(request, response);
            }
    }
}
package exam;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/BookManagementListDisp")
public class BookManagementListDisp extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            response.setContentType("text/html charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println("BookManagementListDisp transition succeeded");
}
}
<%@ page language="java" contentType="text/html;charset=UTF-8"
    pageEncoding="UTF-8"%><%@ page import="exam.LoggerTester" %><% request.setCharacterEncoding("UTF-8");%><% String loginErrorMessage = (String)request.getAttribute("loginErrorMessage");%><!DOCTYPE html><html><head>    <meta charset="UTF-8">        <title>Book management system-<Login></title>        <link rel="stylesheet" href="header.css"></head><header>​<p>Login to book management system</p>​<hr></header><body><%
     LoggerTester lt = new LoggerTester();
     lt.outActionLog("login.jsp", "start processing");
    %>                                    <table border="0">              <form action="Login" method="POST">                                   Used to create a blank. It does not appear on the screen.                                                        Used to create a blank. It does not appear on the screen.                                 <center>               <% if(loginErrorMessage != null){ %>            <p><%= loginErrorMessage %></p>            <%} %>            </center>                                   Used to create a blank. It does not appear on the screen.                                      <p>User ID
                   <input type="text" name="user_id" value="" size="24">                 <p>password
                  <input type="password" name="password" value="" size="24">                <br>                 <input type="submit" name="login" value="login"></form>          </table>            </body><footer><hr></html>
package dao;
import java.io.Serializable;
import java.sql.SQLException;
public class UserDAO implements Serializable {
    // accessor method
    private String _loginid;
    private String _userpassword;
    private int _admin;
    private String _name;
    public void setloginid(String loginid) {
        this._loginid = loginid;
    }
    public String getloginid() {
        return this._loginid;
    }
    public void setuserpassword(String userpassword) {
        this._userpassword = userpassword;
    }
    public String getuserpassword() {
        return this._userpassword;
    }
    public void setadmin(int admin) {
        this._admin = admin;
    }
    public int getadmin() {
        return this._admin;
    }
    public void setname(String name) {
        this._userpassword = name;
    }
    public String getname() {
        return this._name;
    }

    // Get the set information
    public UserDAO selectUser(String loginid, String userpassword) throws ClassNotFoundException,SQLException{
        UserDAO user = new UserDAO();
        user.setloginid("00014");
        user.setuserpassword("aaaaaa");
        user.setadmin(0);
        user.setname("tarou");
        // set return value
        return user;
    }
}
file organization Functions implemented so far

・Determine whether you can log in
・Passing information between DAO and Servlet