You will be fine

<Jsp> 0. Basic

by BFine
반응형

1. Basis

  • 웹서버: 클라이언트의 요청에 따라 html 페이지를 보내고, 웹어플리케이션의 실행 결과를 보여주는 서버

  • MarkUp: Html의 태그를 나타내는 말

  • 웹어플리케이션: html를 생성하는 프로그램




2. Servlet

  • HttpServlet을 상속받는다.

  • doGet, doPost 자동 컴파일

  • Html 전부 보여주는 것이 아닌 결과물만 넘겨준다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Si extends HttpServlet {
    private static final long serialVersionUID = 1L;  
    
    protected void doGet(HttpServletRequest request, 
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        
        response.setContentType("text/html;charset=utf-8"); //한글처리
        PrintWriter out=response.getWriter();
        out.print("<h1>Hello World!</h1>"); //out 브라우저로 전송
        out.close();
        
    }// callback 함수, 자동으로 호출
    
    
    protected void doPost(HttpServletRequest request, 
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
 
}
 
cs



Api

Library-> tomcat -> sevlet-api



3. Method

  • init() : 가장 먼저 실행(한번)

  • doGet() : 요청시 실행 

  • destroy() : 서블릿이 언로드(수정) 될 경우 실행

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        System.out.println("doget");
    }
    @Override
    public void init() throws ServletException {
        // TODO Auto-generated method stub
        
        System.out.println("init");
    } 
    
    @Override
    public void destroy() {
        // TODO Auto-generated method stub
 
        System.out.println("destroy");
    }
 
cs




실행


    


반응형

'공부(2018~2019) - 스킨변경전 > Jsp' 카테고리의 다른 글

<Jsp> 5.useBean, Session, Cookie  (0) 2018.04.19
<Jsp> 4. Action Tags  (0) 2018.04.18
<Jsp> 3. Inner Object  (0) 2018.04.17
<Jsp> 2. Tags  (0) 2018.04.13
<Jsp> 1. Servlet and Html  (0) 2018.04.13

블로그의 정보

57개월 BackEnd

BFine

활동하기