Java C10. Servlet pdf

49 308 0
Java C10. Servlet pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chapter 10. Servlet ITSS Java Programming NGUYEN Hong Quang, HUT Setting of Tomcat plug-ins (1) Setting of Tomcat plug-ins (2) To compile servlet- based program Start and stop of Tomcat Start Tomcat Stop Tomcat Restart Tomcat Servlet execution procedure Creating a project (Tomcat project) Creating a Servlet Registering the Servlet Starting the Servlet Tomcat project Web.xml : configuration file Libraries Servlet program Servlet execution procedure Making of Tomcat project (1) Servlet execution procedure Making of Tomcat project (2) Servlet execution procedure Making of Tomcat project (3) Test Tomcat project by HTML file (1)  Create “test.htm” Servlet execution procedure [...]... procedure Detail of HelloWorldServlet .java (1) import import import import import import java. io.IOException; java. io.PrintWriter; javax .servlet. ServletException; javax .servlet. http.HttpServlet; javax .servlet. http.HttpServletRequest; javax .servlet. http.HttpServletResponse; public class HelloWorldServlet extends HttpServlet { // Initialization of Servlet public void init() throws ServletException { System.out.println("init");... HelloWorldServlet< /servlet- class> < /servlet> Servlet execution procedure Detail of web.xml (2) HelloWorldServlet< /servlet- name> /hello < /servlet- mapping> Servlet Outline    Servlet API, Servlet interface method, Operation principle and lifecycle of Servlet Servlet outline Servlet API servlet configuration information javax .servlet Interface Servlet javax .servlet. .. HttpServlet Definition of HttpServlet class import javax .servlet. *; public class MyHttpServlet extends HttpServlet { // Initialization of Servlet public void init() throws ServletException { … } // Termination of Servlet public void destroy() { … } // Service of Servlet public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { … } public void doPost(HttpServletRequest... Interface Servlet javax .servlet Interface ServletConfig public abstract class GenericServlet public abstract class HttpServlet Servlet outline javax .servlet Interface Servlet  Defines methods that all servlets must implement :  initialize a servlet,  implement service requests,  remove a servlet from the server Servlet outline Life-cycle methods of a servlet    The servlet is constructed, then initialized... Termination of Servlet public void destroy() { System.out.println("destroy"); }} Servlet execution procedure Detail of web.xml (1) HelloWorldServlet< /servlet- name> HelloWorldServlet< /servlet- class>... HttpServlet (1)   Servlet outline An HTTP servlet is using suitable for a Web site A subclass of HttpServlet override usually one of these methods:      doGet, if the servlet supports HTTP GET requests doPost, for HTTP POST requests init and destroy, to manage resources that are held for the life of the servlet getServletInfo, which the servlet uses to provide information about itself getServletConfig,... Eclipse Servlet execution procedure Test Tomcat project by HTML file (7)   Start Tomcat in Eclipse Use a Web Browser to view “test.htm” Servlet execution procedure Creating a Servlet class Servlet execution procedure Registration of Servlet Web.xml and its creation  Create web.xml in WEB-INF directory Run example  Servlet execution procedure When rename URL of a servlet, it must be restart Tomcat Servlet. .. method are handled The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized GenericServlet    Servlet outline GenericServlet implements the Servlet and ServletConfig interfaces It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface To write a generic servlet, you need only override... extends HttpServlet { // Initialization of Servlet public void init() throws ServletException { System.out.println("init"); } Servlet execution procedure Detail of HelloWorldServlet .java (2) // Service of Servlet public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { System.out.println("doGet"); res.setContentType("text/html; charset=utf8"); PrintWriter... limitation in the length of the transmission character string It is possible to transmit only by tag Interface with HttpServlet (1) MyHttpServlet HttpServletRequest Name : Tang Thanh Ha Client : 127.0.0.1 HttpServletResponse Implementation of a HttpServlet Interface with HttpServlet (2) Please enter your name: . javax .servlet. ServletException; import javax .servlet. http.HttpServlet; import javax .servlet. http.HttpServletRequest; import javax .servlet. http.HttpServletResponse; public class HelloWorldServlet extends HttpServlet { //. URL of a servlet, it must be restart Tomcat Servlet execution procedure Detail of HelloWorldServlet .java (1) import java. io.IOException; import java. io.PrintWriter; import javax .servlet. ServletException; import. Tomcat Servlet execution procedure Creating a project (Tomcat project) Creating a Servlet Registering the Servlet Starting the Servlet Tomcat project Web.xml : configuration file Libraries Servlet

Ngày đăng: 28/06/2014, 03:20

Mục lục

  • Setting of Tomcat plug-ins (1)

  • Setting of Tomcat plug-ins (2)

  • Start and stop of Tomcat

  • Making of Tomcat project (1)

  • Making of Tomcat project (2)

  • Making of Tomcat project (3)

  • Test Tomcat project by HTML file (1)

  • Test Tomcat project by HTML file (2)

  • Test Tomcat project by HTML file (3)

  • Test Tomcat project by HTML file (4)

  • Test Tomcat project by HTML file (5)

  • Test Tomcat project by HTML file (6)

  • Test Tomcat project by HTML file (7)

  • Creating a Servlet class

  • Registration of Servlet Web.xml and its creation

  • Life-cycle methods of a servlet

  • Implementation of a HttpServlet

  • Definition of HttpServlet class

  • HTTP method : GET and POST

  • Specification of encoding method

Tài liệu cùng người dùng

Tài liệu liên quan