以下のコードを実行すると画面遷移がうまくいきません。原因はなんでしょうか?
hoge.jps → hogeServlet → fuga.jspの順番になります。
hoge.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>LOGIN</title> </head> <body> <form action = "HogeServlet" method = "POST"> <table> <tr> <td>ID</td> <td><input type="text" name="id"></td> </tr> <tr> <td>Pass</td> <td><input type="password" name="pass"></td> </tr> <tr> <td><input type = "submit" value="login"></td> </tr> </table> </form> </body> </html>
hogeServlet
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; @WebServlet("/HogeServle") public class HogeServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String move = "fuga.jsp"; req.getRequestDispatcher(move).forward(req, resp); } }
fuga.html
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>MENU</title> </head> <body> <h1>LOGIN Success!!</h1> <table border="1"> <tr> <td>LOGIN USER</td> <td>T.Yamada</td> </tr> <tr> <td>LOGIN PASSWORD</td> <td>12qwaszx</td> </tr> </table> </body> </html>
あなたの回答
tips
プレビュー