Introduction to Jsp Technology

1.jsp scripts and comments

  jsp script

    1) <%java code%> -------- The internal java code is translated to the internal of the server method

    2) <%= java variable expression %> ---- will be translated into server internal out.print()

    3) <%! java code%>-- will be translated into the content of the members of the servlet

  jsp comments

    1) Html comment <!--comment content--> ------- visible scope jsp source code, translated servlet, page

    2) java comment//single-line comment/*multi-line comment*/ -- visible range jsp source code translated servlet

    3) jsp comment <%--comment content--%>---visible scope jsp source code is visible

2. JSP operation principle -- the essence of JSP is servlet

  The first time the jsp is accessed / the file is modified, it will be translated into a servlet by the web container and executed (in the servlet in the work folder of the Tconcat server)

  Process:

      The first access/file is modified--->helloServlet.jsp -->helloServlet_.java->compile and run

3.jsp instruction

  1. page command --- the command with the most attributes (the page command defaults in actual development)

    An instruction with the most attributes, according to different attributes, guide the characteristics of the entire page

    Format: <%@ page attribute name 1= "attribute value 1" attribute name 2= "attribute value 2" ...%>

    Common properties are as follows:

    language: the kinds of languages ​​that can be embedded in the jsp script

    pageEncoding: the encoding of the current jsp file---it can contain contentType

    contentType:response.setContentType(text/html;charset=UTF-8)

    session: whether jsp automatically creates a session during translation

    import: package that imports java

    errorPage: which page to jump to when the current page has an error

    isErrorPage: the current page is an error-handling page

  2. include directive

    Page includes (static include) directive, which can include one jsp page into another jsp page

    Format: <%@ include file="Address of included file"%>

  3. taglib directive

    Introduce tag library (jstl tag library, struts2 tag library) into jsp page

    Format: <%@ taglib uri="tag library address" prefix="prefix"%>

4.jsp built-in/implicit objects (9)

  

There is also an exception, error handling

name

Types of

describe

out

javax.servlet.jsp.JspWriter

for page output

request

javax.servlet.http.HttpServletRequest

Get user request information,

response

javax.servlet.http.HttpServletResponse

Response message from server to client

config

javax.servlet.ServletConfig

Server configuration, you can get initialization parameters

session

javax.servlet.http.HttpSession

Used to store user information

application

javax.servlet.ServletContext

Shared information for all users

page

java.lang.Object

Refers to the instance of the Servlet class after the conversion of the current page

pageContext

javax.servlet.jsp.PageContext

JSP page container

exception

java.lang.Throwable

Indicates the exception that occurs in the JSP page, and only works in the error page

  1) The type of out object
           out is jspWriter

      The function is to output the content of the customer service terminal---->out.write();

        The default buffer of out is 8kb, which can be set to 0-->-buffer=“0kb”, and directly write to the response buffer after closing

  2) pageContext object (small important)

    1. The role and nature of the pageContext object

      The context object of the jsp page, the role is as follows

      The page object is not the same thing as the pageContext object

      pageContext is a domain object

    2. Common methods of pageContext object

       1. Access data

      setAttribute(String name,Object obj)

      getAttribute(String name)

      removeAttrbute(String name)

      write/read data to other domains  

      setAttribute(String name,Object obj,int scope)

      getAttribute(String name,int scope)

      removeAttrbute(String name,int scope)

      findAttribute(String name)

      ------- Find the data of the name in all domains, return if found, no longer search, domains from small to large

      -------The pageContext domain->request domain->session domain->application domain in turn

    2.pageContext can get other 8 implicit objects

        Encapsulation for passing parameters

        Calling example:

          pageContext.getRequest()

          pageContext.getSession()

5.jsp tag (action)

    1. Page includes (dynamic include): <jsp:include page="included page">

    2. Request forwarding <jsp:forward page="Resources to be forwarded">

What is the difference between static and dynamic include?

    The static page file is two files translated into one and the dynamic page file is two translated or two people

      

      

     

      

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325127746&siteId=291194637