全く同じコードでも、doGetは成功し、doPostのみ405エラーとなる
servlet
1package servlet; 2 3import java.io.IOException; 4import java.util.List; 5 6import javax.servlet.RequestDispatcher; 7import javax.servlet.ServletException; 8import javax.servlet.annotation.WebServlet; 9import javax.servlet.http.HttpServlet; 10import javax.servlet.http.HttpServletRequest; 11import javax.servlet.http.HttpServletResponse; 12import javax.servlet.http.HttpSession; 13 14import logic.GetQuestionLogic; 15import model.Question; 16 17/** 18 * 質問登録画面へ遷移するservlet 19 */ 20@WebServlet("/QuestionListServlet") 21public class QuestionListServlet extends HttpServlet { 22 private static final long serialVersionUID = 1L; 23 /** 24 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 25 */ 26 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 27 //質問リスト取得 28 GetQuestionLogic getQuestionLogic = new GetQuestionLogic(); 29 List<Question> questionList = getQuestionLogic.execute(); 30 HttpSession session = request.getSession(); 31 session.setAttribute("questionList", questionList); 32 //質問リスト画面へフォワード 33 RequestDispatcher dispatcher = 34 request.getRequestDispatcher("/WEB-INF/jsp/QandAList.jsp"); 35 dispatcher.forward(request, response); 36 } 37 38 protected void doPost(HttpServletRequest request, HttpServletResponse response) 39 throws ServletException, IOException { 40 //質問リスト取得 41 GetQuestionLogic getQuestionLogic = new GetQuestionLogic(); 42 List<Question> questionList = getQuestionLogic.execute(); 43 HttpSession session = request.getSession(); 44 session.setAttribute("questionList", questionList); 45 //質問リスト画面へフォワード 46 RequestDispatcher dispatcher = 47 request.getRequestDispatcher("/WEB-INF/jsp/QandAList.jsp"); 48 dispatcher.forward(request, response); 49 } 50} 51 52
jspのformからsubmitボタンを押下する際、methodをpostにした場合のみ
エラーが発生します。
原因分かりましたらご教示いただけますでしょうか。
回答1件
あなたの回答
tips
プレビュー