ecsimsw
Servlet / get & post 본문
get / post
doPost에서는 request를 받아서 doGet(request, response) 형태로 doGet 호출
get, post 요청 차이는 https://ecsimsw.tistory.com/entry/GET-POST 에서 node.js 공부할 때 정리해두었다.
예시)
@WebServlet("/login")
public class ServletEX extends HttpServlet {
private static final long serialVersionUID = 1L;
public ServletEX() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
String id = request.getParameter("id");
String pw = request.getParameter("pw");
System.out.println("id : " + id + " pw : "+pw);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
1. get
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Ecsimsw</title>
</head>
<body>
<form action= "login">
<p>
<strong>아이디</strong>
<input type="text" name="id" value="아이디 입력">
</p>
<p>
<strong>비밀번호</strong>
<input type="password" name="pw" value="비밀번호 입력">
</p>
<p>
<input type="submit" value="제출">
</p>
</form>
</body>
</html>
method를 지정하지 않아 get으로 처리
http://localhost:8090/helloJSP/login?id=Jinhwan&pw=kim
2. Post
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Ecsimsw</title>
</head>
<body>
<form action= "login" method ="post">
<p>
<strong>아이디</strong>
<input type="text" name="id" value="아이디 입력">
</p>
<p>
<strong>비밀번호</strong>
<input type="password" name="pw" value="비밀번호 입력">
</p>
<p>
<input type="submit" value="제출">
</p>
</form>
</body>
</html>
http://localhost:8090/helloJSP/login
결과 화면
id : Jinhwan pw : kim
'Server application > Web, Servlet' 카테고리의 다른 글
WEB / HTTP 메시지 구조 (0) | 2020.05.11 |
---|---|
WEB / URL 예약 문자와 인코딩 (0) | 2020.05.11 |
Servlet 생명 주기 (0) | 2020.05.10 |
Servlet mapping (0) | 2020.05.10 |
JSP / 초기 설정 (0) | 2020.05.09 |
Comments