重定向登入跳轉
阿新 • • 發佈:2021-07-13
登入跳轉
index
index <html> <body > <%@ page contentType="text/html; charset=UTF-8" %> <h2>Hello World!</h2> <form action="${pageContext.request.getContextPath()}/res" method="get"> 使用者名稱: <input type="text" name="username" ><br> 密 碼: <input type="text" name="password" ><br> <input type="submit"> </form> </body> </html>
Request
package com.xin; import com.sun.net.httpserver.Authenticator; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class RequestText extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String username = req.getParameter("username"); String password = req.getParameter("password"); resp.sendRedirect("Success.jsp"); System.out.println(username+":"+password); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } }
Success跳轉成功
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Success</title>
</head>
<body>
<h1>Success</h1>
</body>
</html>