반응형

Java Web Application

           

  1. Web Server and Client
  2. HTML and HTTP
  3. Understanding URL
  4. Why we need Servlet and JSPs?
    Web servers are good for static contents HTML pages but they don’t know how to generate dynamic content or how to save data into databases
    Servlet/JSP: server side technologies to extend the capability of web servers
    ASP, PHP, CGI...

  5. Web Container
    1. Communication Support – provides easy way of communication between web server and the servlets and JSPs. We don’t need to build a server socket to listen for any request from web server, parse the request and generate response.
    2. Lifecycle and Resource Management – takes care of managing the life cycle of servlet. (loading the servlets into memory, initializing servlets, invoking servlet methods and destroying them)
    3. Multithreading Support – creates new thread for every request to the servlet and when it’s processed the thread dies. So servlets are not initialized for each request and saves time and memory.
    4. JSP Support – Every JSP is compiled by container and converted to Servlet.
    5. Miscellaneous Task – manages the resource pool, does memory optimizations, run garbage collector, provides security configurations, support for multiple applications, hot deployment and several other tasks.
  6. Web Application Directory Structure (Java Servlet API requirements)

    WEB-INF  is a private directory, but  accessible to the resource loader of Web-Application.
    META-INF is related to .jar files, contains the manifest (main class, security policy, component info, sealing info...) of a jar and is created when you write a jar file. 
  7. Deployment Descriptor web.xml file 
    mapping for servlets-URL (prior to 3.0), welcome/error pages, security configurations, listener, filter, session timeout settings etc.

 

Servlet (https://www.journaldev.com/1877/servlet-tutorial-java)

JEE server driven technology (javax.servlet, javax.servlet.http)

  • better performance-multithreading
  • platform independent
  • robust because container takes care of life cycle of servlet and we don’t need to worry about memory leaks, security, garbage collection etc.
  • maintainable and learning curve is small

 

  • ① 사용자가 URL을 클릭하면 HTTP Request를 Servlet Container에 보낸다.
  • ② Servlet Container는 HttpServletRequest, HttpServletResponse 두 객체를 생성한다.
  • ③ 사용자가 요청한 URL을 분석하여 어느 서블릿에 대한 요청인지 찾는다. (DD를 참조하여 분석)
  • ④ 컨테이너는 서블릿 service() 메소드를 호출하며, POST, GET여부에 따라 doGet() 또는 doPost()가 호출된다.
  • ⑤ doGet() or doPost() 메소드는 동적인 페이지를 생성한 후 HttpServletResponse객체에 응답을 보낸다.
  • ⑥ 응답이 완료되면 HttpServletRequest, HttpServletResponse 두 객체를 소멸시킨다.

 

    • Servlet Interface
    • ServletConfig Interface
    •  

ServletContext interface

    •  

    •  

ServletRequest interface

    •  

    •  

ServletResponse interface

    •  

    •  

RequestDispatcher interface

    •  

    •  

GenericServlet class

    •  

    •  

HTTPServlet class

  •  

inter-servlet communication

  • RequestDispatcher.forward: request를 다른 servlet으로 보내는데 container에서 내부적으로 처리됨
    • The path must begin with a / and is interpreted as relative to the current context root. (/로 시작해야하는 제약....이런건 왜......)
  • Response.sendRedirect: 302 redirect address를 보내고 다시 browser가 그 주소로 요청


RequestDispatcher.forwardResponse.sendRedirect

brower가 redirection을 알 수 없다 알 수 있다
other context로 보낼수 없다 있다
extra network call 발생안함 발생함
  • RequestDispatcher.forward: request를 다른 servlet으로 보냄
  • RequestDispatcher.include: response가 다른 servlet에 포함되도록 보냄

Servlet attributes (!=init parameters defined in web.xml)

  • request scope: ServletRequest provide methods to get/set/remove attributes
  • session scope: HttpSession 
  • application scope: ServletContext 
반응형

'java, spring' 카테고리의 다른 글

Quartz  (0) 2022.04.19
Tomcat's directories  (0) 2021.03.03
tomcat  (0) 2021.03.02
spring-boot profile별 실행  (0) 2020.03.25
java time - Instant, LocalDate  (0) 2020.03.16

+ Recent posts