Created
December 10, 2019 06:34
-
-
Save ksy90101/d4604ba243d4b321dd656b5310231d7d to your computer and use it in GitHub Desktop.
[부스트코스] 웹 프로그래밍 > 1 > 5 > Servlet 라이프 사이클
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import javax.servlet.ServletConfig; | |
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("/LifecycleServlet") | |
public class LifecycleServlet extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
public LifecycleServlet() { | |
System.out.println("LifecycleServlet 생성!"); | |
} | |
public void init(ServletConfig config) throws ServletException { | |
System.out.println("init 호출!"); | |
} | |
public void destroy() { | |
System.out.println("destroy 호출!"); | |
} | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
System.out.println("service 호출!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.servlet.ServletConfig; | |
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("/LifecycleServlet2") | |
public class LifecycleServlet2 extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
public LifecycleServlet2() { | |
System.out.println("LifecycleServlet 생성!"); | |
} | |
public void init(ServletConfig config) throws ServletException { | |
System.out.println("init 호출!"); | |
} | |
public void destroy() { | |
System.out.println("destory 호출!"); | |
} | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
response.setContentType("text/html;charset=utf-8"); | |
PrintWriter out = response.getWriter(); | |
out.println("<html>"); | |
out.println("<head><title>form</title></head>"); | |
out.println("<body>"); | |
out.println("<form method='post' action='LifecycleServlet2'>"); | |
out.println("name : <input type='text' name='name'><br/>"); | |
out.println("<input type='submit' value='ok'><br/>"); | |
out.println("</form>"); | |
out.println("</body>"); | |
out.println("</html>"); | |
out.close(); | |
} | |
@Override | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
response.setContentType("text/html;charset=utf-8"); | |
PrintWriter out = response.getWriter(); | |
String name = request.getParameter("name"); | |
out.println("<h1>hello" + name + "</h1>"); | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment