Analysis of jsp knowledge points in javaweb

Analysis of jsp knowledge points

javaWEB Smile

   a JSP

        JavaScript code

            Notes

                Implicit comments
                    //Single-line comments
                    /* */ Multi-line comments
                    <%-- Comments--%>
                Display comments
                    <!-- Comments-->
        java code
            <% %> Local variables, writing statements are equivalent to <jsp: script></jsp:script>
            <%! %> Global variables, methods, classes
            <%= %> Output a variable or a specific constant
        page command
            to generate a session <%@ page session="true|false"%>
            statement Attributes<%@page attribute="content"%>
            page encoding
                 <%page language="java" contentType="text/html;charset=utf-8"%>
                <%@page contentType="text/html"     pageEncoding="utf-8"%>
            Error page
                Jump to the error page: <%@page erroePage="erro.jsp"%>
                Error page authentication: <%page isErrorPage="true" %>
        Include
            static include (include first and then process): <%@include file="Yes Included file path"%>
            Dynamic inclusion (included after processing) <jsp:include>
        Jump instruction
            Client jump
                a link <a href="#" />
                Redirect
                    rsponse.setStatus(302); rsponse.setHeader ("Location","hello.jsp");
                    response.setHeader("refresh","2;URL=hello.jsp");
                    response.sendRedirect("hello.jsp");
            Server jump
                request forwarding RequestDispatcher rd=request.getRequestDispatcher("/IServlet").forward(request,response);
                The request contains request.getRequestDispatcher("/IServlet").include(request,response);
                jump instruction <jsp:forward>
    JSP nine built-in
        objects
            pageContext
            request
            response
            session
            application
            config
            out
            page
            exception
            common method
                public void setAttribute(String name,Object)
                public void getAttribute(String name)
                public void removeAttribute(String name)
        Common objects and their methods
            request
                public String getParameter(String name)
                public String[] getParameterValues(String name)
                public Enumeration getParameterNames()
                public String getServletPath()
                public getContextPath()
                public Httpsession getSession()
                public Cookie[] getCookies()
                public String getRemoteAddr()
                void setCharacterEncoding(String env) throws UnsupportedEncodingException
                public boolean isUserInRole(String role)
                public StringBuffer getRequestURL()
                public Enumeration getHeaderNames()
                public String getMethod()
            response
                public void addCookie(Cookie cookie)
                public void setHeader(String name,String value)
                public void sendRedirect(String location) throws IOException
            Cookie
                public Cookie(String name,String value)
                public String getNames()
                public String getValue()
                public void setMaxAge(int expiry)
            session
                public String getId()
                public long getCreationTime()
                public long getLastAccessedTime()
                public boolean isNew()
                public void invalidate()
                public Enumeration getAttributeNames()
            pageContext
                public abstract void forward(String relativeUrlPath) throws ServletException,IOException
                public void include(String relativeUrlPath) throws ServletException,IOException
                public ServletConfig getServletConfig()
                public ServletContext getServletContext()
                public ServletRequest getRequest()
                ublic ServletResponse getResponse()
                public HttpSession getSession()
            application
                String getRealPath(String path)
                public Enumeration getAttributeNames()
                public String getContextPath()
            config
                public String getInitParameter(String name)
                public Enumeration getInitParameterNames()
            out
                public int getBufferSize()
                public int getRemaining()
    javaBean
        function
        name (three types)
            POJO(Plain ordinary Java Objects): A simple Java object
            VO (Value Object) is used to transfer the value
            TO (Transfeers Object) to transfer objects, and remote transmission needs to implement the Serializable interface
        instruction
            Instantiate Bean: <jsp:usebean id="Instantiated object name" scope="Save scope" class="Package.ClassName" />
                JavaBean
                    package.Class
                    class declaration public class
                    Encapsulation attribute private
                    Provide setter, getter
                    at least one None Parameter constructor
                javaBean scope
                    page
                    request
                    session
                    application
            set properties
                to automatically match <jsp:setproperty name="The name of the instantiated object (id)" property="*" />
                Specified properties <jsp:setProperty name="The name of the instantiated object (id)" property="property name" />
                Specified parameter <jsp:setProperty name="Name of instantiated object (id)" property="Property name" param="Parameter name" />
                Specified content <jsp:setProperty name="Name of instantiated object (id)" property="property name" value="content">
            Get property
                <jsp:getProperty name="Name of the instantiated object (id)" property="Property name" /> JavaBean
            delete
                delete page JavaBean
                    pageContext.removeAttribute(JavaBean Name)
                delete the request's JavaBean
                    request.removeAttribute (JavaBean name)
                delete the session's JavaBean
                    session. removeAttribute(JavaBean name)
                deletes the application's JavaBean
                    application.removeAttribute(JavaBean name)
    Expression Language (Expression Language)
        uses ${attribute name}
        built-in objects
            11 built-in objects
                pageContext
                pageScope
                requestScope
                sessionScope
                applicationScope
                param
                paramValues
                ​​header
                headerValues
                ​​cookie
                initParam
            built-in object operations
                refer to JSP built-in object method
                reference webpage: https://blog. csdn.net/hon_3y/article/details/54890071
        Access the content search order of 4 attribute ranges
            : page->request->session->application
            ${pageScope.property}
            ${requestScope.property}
            ${sessionScope.property}
            ${applicationScope.property}
        Data operation
            receives request parameters
                ${param.parameter name}
                Receives a set of parameters ${paramValues.parameter name}
            collection operation
                List and Set operation
                Map operation
            operator
                Arithmetic operator
                    + like ${20+30}
                    - like ${30-20}
                    * like ${20*30}
                    / or div like ${30 div 20}
                    % or mod like ${ 30 mod 30}
                relational operator
                    == or eq ${30 eq 20}
                    != or ne as ${30 ne 20}
                    <or lt as ${20 lt 30}
                    > or gt as ${30 gt 20}
                    <= or le as ${20 le 30}
                    >= or ge as ${30 ge 20}
                Logical operators
                    && or and such as ${true && true}
                    || or or such as ${true || false}
                    ! or not such as ${!true}
                other operators
                    empty such as ${empty info}
                    ?: such as ${10>20?"Greater than":"Less than"}
                    () Such as ${10*(20+30)}
    JSTL(JSP Standard Tag Library)
        preparation
            import WEBINF/lib
                jstl.jar
                The standard.jar
            jsp header introduces JSTL instructions
                 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
        JSTL core library
            <c:out>
            <c: set>
            <c:remove>
            <c:catch>
            <c:if>
            <c:choose>, <c:when>, <c:otherwise>
            <c:forEach>
            <c:forTokens>
            <c:import
            <c :url>
            <c:redirect>
        Internationalized Tag Library
            Internationalized Tag Library
                <fmt:setLocale>
                <fmt: requestEncoding>
            information display library
                <fmt:bundle>
                <fmt:message>
                <fmt:setbundle>
            Number and date formatting
                <fmt:formartNumber>
                <fmt:parseNumber>
                <fmt:formartDate>
                <fmt:parseDate>
                <fmt:setTimeZone>
                <fmt:timeZone>
        SQL Tag Library
            Data Source Tag
                <sql:setDataSource>
            Database Operation Tag
                <sql:query>
                <sql:update>
            Transaction Tag

                <sql:transaction>


The above was originally a mind map organized in the past few days, and it is pasted in full format, so let's take a look!

SmileIt is worth noting that jsp is essentially a servlet. We can see that the compiled jsp is a .class file in the work directory under the tomcat directory, which also shows that

There is also an object in jsp, which is the servlet instance object represented by this. Through this, we can do things that servlets can do, such as getting the real path under the virtual path.

<%

String path = this.getServletContext(.getRealPath("/")); 

//Note that the ServletContetx here is actually the current environment, the web container, through which we can get the real path

%>

Regarding the real path and virtual path, we can see in the web.xml file of tomcat

<Context path="virtual path" docBase="real path" />,

The virtual path is what we type on the browser address bar, and the real path is the address that exists on our local hard drive.

Guess you like

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