Learning of Java Web Servlet



Java Web Servlet beginning of the study we first take a look at what Java Web that contains it? A complete Java Web usually by the presentation layer, control layer, business layer and data access layer. The presentation layer is usually constructed from the HTML and JSP pages, control is generally used Servlet, JavaBean business logic is or EJB, JDBC data access layer components or Hibernate.Java Web in the configuration file of each component (. xml) in the package declaration, deployed to the Java Web server (Tomcat ...) to run.

Java Web Servlet is a server-side program written in java, because it is a Java class, with a portable, scalable, and so on. Javax.servlet and javax.servlet.http packages received through the Java support. Especially the javax.servlet.http packageHTTP protocol provides a method for including the handling of HTTP requests and responses (HttpServlet class), respectively, by the doGet () and doPost () for processing.

Java code

protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException; protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException;

The processing of requests for customers (HttpServletRequest class)

Java code

HttpServletRequest request; String name = request.getParameter ("username");

HTML form to send the request to the client (HttpServletResponse class)

Record the current user session in Servlet (HttpSession class)

Java code

HttpServletRequest request; HttpSession session = request.getSession (true);

Servlet's request to submit or assigned to another resource (RequestDispatcher class), RequestDispatcher to a specific resource URL, HttpServletRequest object by getRequestDispatcher () method to generate.

Java code

RequestDispatcher rd = request.getRequestDispatcher ("WELCOME.JSP"); rd.forward (request, response);

As in the Java Web Servlet as the controller components normally required in the configuration file (web.xml) in the statement.

Java code

web.xml

... MyServlet myServlet myServlet / myServlet ...

Java Web Servlet interspersed study is to consolidate learning, to infiltrate in the Java Web Servlet study, Hope this helps.