以下のjspからExecuteLoginを呼び出そうとすると404になってしまいます。
どうすれば改善するでしょうか。
![]
Login.jspのコード
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>ログイン画面</title> </head> <body> <h1>ログイン画面</h1> <form action = "<%=request.getContextPath() %>/ExecuteLogin" method="post"> <p>ユーザーID: <input type ="text" name="USER_ID" maxlength="20"> </p> <p>パスワード: <input type ="text" name="PASSWORD" maxlength="20"> </p> <input type="submit" value="ログイン"> </form> </body> </html>
ExecuteLoginのコード
package controller; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import model.BusinessLogic; import model.UserInfoDto; public class ExecuteLogin extends HttpServlet { private static final long serialVersionUID = 1L; public ExecuteLogin() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); UserInfoDto dto = (UserInfoDto)session.getAttribute("LOGIN_INFO"); if(dto != null) { response.sendRedirect("/WebContent/WEB-INF/view/Input.jsp"); }else { String userId = request.getParameter("USER_ID"); String passWord = request.getParameter("PASSWORD"); //BusinessLogic呼び出し(情報の照合) BusinessLogic logic = new BusinessLogic(); UserInfoDto userInfoDto = logic.executeLoginCheck(userId,passWord); //結果による振り分け if(userInfoDto.getUserId() != null) { session.setAttribute("LOGIN_INFO",userInfoDto); request.setAttribute("LOGIN_INFO", userInfoDto); RequestDispatcher dispatch = request.getRequestDispatcher("/WebContent/view/Input.jsp"); dispatch.forward(request,response); response.sendRedirect("/WebContent/view/Input.jsp"); }else { response.sendRedirect("/WebContent/view/Login.jsp"); } } } }
回答2件
あなたの回答
tips
プレビュー