Содержание
- 2. Lesson goals Client-Server Static vs dynamic content Java Servlet Tomcat
- 3. Client-Server architecture A person enters a URL string into the browser. The browser generates HTTP-request. The
- 4. Client-Server architecture • Web-server for static content (popular): Apache, nginx, GWS, IIS, ... • Software for
- 5. CGI - Common Gateway Interface Standard used to communicate of the web server with an external
- 6. CGI - Common Gateway Interface Shortcomings of CGI technology: ● Start an OS process for each
- 7. Http Servlet service(HttpServletRequest, HttpServletResponse) doGet(HttpServletRequest, HttpServletResponse) doPost(HttpServletRequest, HttpServletResponse)
- 8. Java Servlet @WebServlet(name = "helloServlet", urlPatterns = {"/hello"}) public class HelloServlet extends HttpServlet { public void
- 9. Java Servlet 4.0 HTTP /2 Request/Response multiplexing Stream Prioritization Server Push Upgrade from HTTP 1.1
- 10. Servlet Lifecycle Loads the servlet class Creates an instance of the servlet class Initializes the servlet
- 11. HttpServletRequest Container creates HttpServletRequest object and passes it as argument to Servlet's service methods (doGet, doPost,
- 12. HttpServletRequest Methods: - getHeader (String) - getParameter (String) - getInputStream () - getSession () - getServletContext
- 13. HttpServletResponse Container creates HttpServletResponse object and passes it to Servlet's service methods (doGet, doPost, etc.) HttpServletResponse
- 14. HttpServletResponse Methods: - addHeader (String, String) - setStatus (int) - sendError (int) - sendRedirect (String) -
- 15. HttpSession HttpSession session = request.getSession(); Main methods: - invalidate () - getAttributeNames () - getAttribute (String)
- 16. ServletContext Servlet uses ServletContext to communicate with its servlet container, access the servlet container. ServletContext sc
- 17. Filter @WebFilter(urlPatterns = {"/*"}) public class HelloFilter implements Filter { public void init(FilterConfig cfg) { }
- 18. Error Handling @WebServlet("/error") public class ErrorHandler extends HttpServlet { private static final long serialVersionUID = 1L;
- 19. Error Handling Web Project java.lang.RuntimeException /error
- 20. Web (servlet) container A Web server - component that interacts with Java Servlets. Primary responsibilities are:
- 21. Java EE & Servlet (Web) Container Most popular Servlet (Web) Containers • Apache Tomcat • Jetty
- 22. Apache Tomcat
- 23. WAR Web application ARchive - is a JAR file used to distribute a collection of JavaServer
- 24. WAR
- 25. Literature Building Java Web Applications Servlets (by Baeldung) Servlets (by Tutorialspoint) How to Install Apache Tomcat
- 26. Homework Task 1 Implement a servlet with interface: `/session?action=[add/update/remove/invalidate]&name=...&value=...` 1. The servlet generates a form with
- 28. Скачать презентацию