티스토리 뷰
1.doPost방식
<Servlet>
- package ex.mystudy.ex;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Calendar;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Servlet implementation class HelloWorle
- */
- @WebServlet(name = "HelloWorld", urlPatterns = { "/HW" })
- public class HelloWorld extends HttpServlet { //서블릿은 HttpServlet을 상속받는다
- private static final long serialVersionUID = 1L;
- public HelloWorld() {
- super();
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- //response.getWriter().append("Served at: ").append(request.getContextPath());
- //응답시 한글처리를 위한 문자셋 지정
- response.setContentType("text/html; charset=UTF-8");
- out.println("<!DOCTYPE html>");
- out.println("<html>");
- out.println("<head>");
- out.println("<title>서블릿예제</title>");
- out.println("</head>");
- out.println("<body>");
- out.println("<p>오늘의 날짜는?</p>");
- out.println(year + "년" + month + "월");
- out.println("</body>");
- out.println("</html>");
- out.close();
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doGet(request, response);
- }
- }
-> consol창
-> 결과창
-doPost방식
<HTML>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>폼</title>
- </head>
- <body>
- <form action="PostMethod" method="post">
- <input type="submit" value="post">
- </form>
- </body>
- </html>
- 서블릿의 PostMethod를 찾아간다
<Servlet>
- package ex.mystudy.ex;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Servlet implementation class post
- */
- @WebServlet("/PostMethod")
- public class post extends HttpServlet {
- private static final long serialVersionUID = 1L;
- public post() {
- super();
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- response.setContentType("text/html; charset=UTF-8");
- out.println("<!DOCTYPE html>");
- out.println("<html>");
- out.println("<head>");
- out.println("<title>--> doPost</title>");
- out.println("</head>");
- out.println("<body>");
- out.println("<h1>doPost방식인뎁쇼</h1>");
- out.println("</body>");
- out.println("</html>");
- }
- }
-> 콘솔창
-> 결과창
post버튼 클릭
'JSP' 카테고리의 다른 글
[JSP] Request, Response 간단한 회원가입창 예제 (0) | 2018.07.10 |
---|---|
[JSP] Request, Response 객체 (0) | 2018.07.10 |
[JSP] Servlet - form값 받기 (0) | 2018.06.21 |
[JSP] Servlet - init, destory, @PostConstruct, @PreDestroy (0) | 2018.06.20 |
[JSP] 개념? (0) | 2018.06.20 |
댓글
최근에 올라온 글
최근에 달린 댓글
링크
- Total
- Today
- Yesterday