当前位置:网站首页>JSP Basics

JSP Basics

2022-06-21 18:50:00 LvhaoIT

JSP Basic knowledge

One 、JSP Specification introduce

  • From JAVAEE One of the specifications

  • JSP The specification sets out how to develop JSP Instead of the response object, the file writes the processing results to the development process of the response body

  • JSP The specification is formulated Http How the server should invoke Management JSP file

Two 、 The response object has drawbacks

  • It is suitable for writing processing results with less data to the response body

  • If the number of processing results is too large , Using response objects makes development more difficult

3、 ... and 、JSP File advantage

  • JSP Documents in the Internet communication process , Is a response object substitute .

  • Reduce the development workload of writing the processing results to the response body, and reduce the difficulty of maintaining the processing results

  • stay JSP File development , The processing results can be written directly to JSP Documents do not need to be handwritten out.print command , stay Http Server calls JSP When you file , according to JSP The specification requires that JSP All contents written by the file are written to the response body through the output stream

Four 、HTML File with the JSP File differences

  • As a resource, the file type is different

    HTML The file is a static resource file , Its related commands need to be compiled and executed in the browser .

    JSP This file is a dynamic resource file , Its related commands need to be compiled and executed on the server

  • The call form is different

    If the browser accesses HTML file , here Http The server passes directly through an output stream

    take HTML All contents of the file are written to the response body

    If the browser accesses JSP file . here Http Server according to JSP Specification to operate JSP File editing ----> compile -----> call

5、 ... and 、Http Server calls JSP File steps :

1.Http Server will JSP The contents of the document 【 edit 】 For one Servlet Interface implementation class (.java)
2.Http Server will Servlet Interface implementation class 【 compile 】 by class file (.class)
3.Http The server is responsible for creating this class Instance object of , The instance object is Servlet Instance object
4.Http Server pass Servlet Instance object call _jspService Method , take jsp The contents of the file are written to the response body

6、 ... and 、Http The server 【 edit 】 And 【 compile 】JSP file location :

stay 【work】 See this evidence next

C:\Users[ Sign in windows System user role name ].IntelliJIdea2018.3\system\tomcat[ Web workspace ]\work\Catalina\localhost\【 Website alias 】\org\apache\jsp

7、 ... and 、 stay JSP How to write in the document Java command

1. Execution tag

<% %>

2. Command format

<% int a  =10;  %>  Declare local variables 
    <% boolean flag = 30 >= 40; %>  Java The expression in ( Mathematical expression , Relationship expression , Logical expression )
        <%
        if( Judge the condition ){

        }else{

        }

while(){

}

%>   Write control statements 

3. Command function

​ notice Tomcat Put the output in the tag 【 The value of the variable 】 Or in the output tag 【 The result of the expression operation 】 Write to the response body

8、 ... and 、 How to integrate Servlet in doGet/doPost Method execution results to JSP File output

  • JSP When a file is accessed , Not at all JSP The file is executing . It's the corresponding Servlet In execution

  • Customize Serlvet Interface implementation class and JSP Calling relationship between files , Equivalent to two Servlet Call relationship between

  • Customize Servelt Interface implementation class and JSP The files can be called through the redirection scheme or the request forwarding scheme. Considering the running efficiency , It is generally used 【 Request forwarding 】

  • Customize Servlet The interface implementation class can hand over the shared data to... By requesting the scope object JSP To output to the response body

原网站

版权声明
本文为[LvhaoIT]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211712399298.html