JSP

1. Introduction

  JSP(Java Server Page )It is a dynamic webpage programming technology provided by SUN, and is a dynamic resource of Java Web server side.

  JSPTechnology can provide:

    ·htmlStatic page

    ·Allow Java code to be nested in the page to provide dynamic data.

    ·Easy to Typesetting data.

    

    When the Jsp is first accessed, the Jsp engine translates the Jsp into a servlet, which is stored in the work directory in Tomcat.

 

Two. Basic grammar

  1、Notes

    Display annotations (allowing clients to see):

      <!– HTMLStyle annotation –>

    Implicit annotation (invisible to the client):

      //Single line annotation / * multiple lines of notes * /

      <%– JSPNote –%>

 

  2、Scriptlet(Script applet)

    Java programs embedded in HTML code must be marked with scriptlets. There are three types of scriptlet code:

      1、<%   %> 

        javaScript segments, you can define local variables and write statements.

        javaThe code will be in the service method of the compiled servlet.

        

 

      2、<%!   %>

        Declarations, you can define global (member) variables, methods, and classes.

        

 

      3、<%=   >

        Expression, output a variable or specific content.

        

 

Three, JSP instruction labels

  JSPThe command tag is used to control the behavior of the entire jsp, indicating some aspects of the current JSP page to the JSP converter.

  

  1、pageinstructions

    MIMEtype

      language=”java”,The current use of Java language, currently only Java

      contentType=”text/html;charset=UTF-8″ Page response type and encoding

      pageEncoding=”UTF-8″,Page coding

      Page encoding is first found in charset in contentType, but not in pageEncoding. It does not exist. The default is ISO-8859-1.

 

    Guide bag: it can appear many times.

      

 

  2、includeStatic inclusion

    

      (1)Static includes loading pages directly loaded into the current page.

      (2)jspThe compiled files are generated in a servlet service method, so there is no namespace variable.

      (3)When the file attribute value is set, the path is written wrongly.

      (4)Only one source file is generated after being compiled.

    Advantages and disadvantages:

      The operating efficiency will be slightly higher.

      High degree of coupling and inflexibility

    

  3、taglibImport tag library

    

 

Four, JSP action tab

  Action labels, which are compiled into Java code for performing an operation. JSP containers have their own standard actions to support and can also create specified labels to perform certain operations.

  ·Action tags are interpreted by Tomcat (server), and are executed on the server side as well as Java code.

  ·htmlImplemented by browser

    

 

  includeDynamic inclusion

    1、The dynamic contains calls equivalent to the method, and the two pages are independent.

    2、You can have the same name variable.

    3、The corresponding number of source files will be generated.

    4、Dynamic contains double tags, which can pass parameters, do not transfer parameters, do not add anything.

    5、Reduce coupling, more flexible.

 

    Dynamic include transfer parameters

      

      The receiving parameters are completed by request.getParameter (name).

    

Five, nine built-in objects

  1、requestobject(Same as request in servlet)

    Including header information, system information, request method, request parameters, etc., request object scope is a request

  2、responseobject

    For client response, response objects also have scopes, which are valid only in JSP pages.

  3、sessionobject

    An object that is automatically created by the server and related to the user request.

  4、applicationobject

    applicationThe information stored in the object is valid throughout the application.

  5、outobject

    It is used to output information in web browser and manage output buffer on application server.

      out.write(); out.close();

  6、pageContextobject

    The role is to get any range of parameters.

  7、configobject

    The main function is to get the configuration information of the server.

  8、pageobject

    Representing the JSP itself is legal only within the JSP page, and the implied object essentially contains variables referenced by the current Servlet interface, similar to this pointer in Java programming

  9、exceptionobject

 

  

    exceptionobject

      ·Set the page to which the error should be skipping.

      ·Configure in XML file

        

 

      

  

 

Leave a Reply

Your email address will not be published. Required fields are marked *