Home  >  Article  >  Java  >  Getting Started with JSP Basics

Getting Started with JSP Basics

巴扎黑
巴扎黑Original
2017-07-24 14:10:281482browse

The essence of JSP is a Servlet source program

When each JSP page is accessed for the first time, the JSP engine translates it into a Servlet source program, and then Compile this Serlvet source program into a Servlet class file.

Then the Web container (Servlet engine) loads, interprets and executes the Servlet program in the same way as calling a normal Servlet program.

Implicit variables of JSP pages

Variables that have been declared, we don’t need to declare them ourselves.

There are 9 hidden objects in total.

  1. HttpServletRequest request

  2. HttpServletResponse response (response is almost never called in a JSP page any method)

  3. PageContext pageContext: The context of the page. You can get the other 8 implicit objects from this object, and you can also get other objects of the current page. Information

  4. HttpSession session: A conversation between the browser and the server

  5. ServletContext application: Represents the current Web application

  6. ServletConfig config: ServletConfig object of the Servlet corresponding to the current JSp (almost not used)

  7. JspWriter out: out.println() can print the string directly to the browser

  8. Object page: points to the current JSP A reference to the corresponding Servlet object, but because of the Object type, only methods of the Object class can be called (almost not used)

  9. Exception exception: In the statement where the page directive is declared isErrorPage="true" can only be used. <% page isErrorPage="true" %>

pageContext, request, session, application (the scope of the attribute is smaller than to large)

JSP expression

<%= xxx %>

JSP declaration

<%! %>The java code in will be inserted outside the jspServlet method of the Servlet, So the JSP declaration can be used to define the Servlet program that the JSP page is converted into static code blocks, member variables and methods.

Because JSP implicit objects are declared within the jspServlet method, so these implicit objects cannot be used in JSP declarations.

JSP Comments

<%-- --%>

The above is the detailed content of Getting Started with JSP Basics. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn