JSP/SERVLET
chapter09 : request.java / input.jsp , output.jsp
GAWON
2023. 5. 23. 18:58
package org.joonzis.ex;
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("/pagemove")
public class Ex09_servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public Ex09_servlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=UTF-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
request.setAttribute("id", id);
request.setAttribute("pw", pw);
//포워드 방식으로 데이터를 가져온다
request.getRequestDispatcher("Ex09_output.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- pagemove : Ex09_servlet.java
서블릿의 URLMapping 값
-->
<form action="/chapter03_servlet/pagemove">
<h1>로그인</h1>
<p>아이디<input type="text" name="id"></p>
<p>비밀번호<input type="password" name="pw"></p>
<input type="submit" value="전송">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
id : ${id }
pw : ${pw }
</body>
</html>