Introduction to JSP

Source: Internet
Author: User

My first JSP file is a very simple JSP file, as shown below:

<% @ Pageimport = "java. util. Date" %>

<% @ Page language = "java" contentType = "text/html; charset = UTF-8"

PageEncoding = "UTF-8" %>

JSP

<% = "Hello" %>

I am using the Tomcat7.0 server. After being loaded to Eclipse, I will compile the JSP file above and compile the JSP file into

Servlet java files, such:

Package org. apache. jsp;

Import javax. servlet .*;

Import javax. servlet. http .*;

Import javax. servlet. jsp .*;

Import java. util. Date;

Public final class index_jsp extends org. apache. jasper. runtime. HttpJspBase

Implements org. apache. jasper. runtime. JspSourceDependent {

Private static final javax. servlet. jsp. JspFactory _ jspxFactory =

Javax. servlet. jsp. JspFactory. getdefafactory Factory ();

Private static java. util. Map _ Jspx_dependants;

Private javax. el. ExpressionFactory _ el_expressionfactory;

Private org. apache. tomcat. InstanceManager _ jsp_instancemanager;

Public java. util. Map GetDependants (){

Return _ jspx_dependants;

}

Public void _ jspInit (){

_ El_expressionfactory = _ jspxFactory. getJspApplicationContext (getServletConfig (). getServletContext (). getExpressionFactory ();

_ Jsp_instancemanager = org. apache. jasper. runtime. InstanceManagerFactory. getInstanceManager (getServletConfig ());

}

Public void _ jspDestroy (){

}

Public void _ jspService (final javax. servlet. http. HttpServletRequest request, final javax. servlet. http. HttpServletResponse response)

Throws java. io. IOException, javax. servlet. ServletException {

Final javax. servlet. jsp. PageContext pageContext;

Javax. servlet. http. HttpSession session = null;

Final javax. servlet. ServletContext application;

Final javax. servlet. ServletConfig config;

Javax. servlet. jsp. JspWriter out = null;

Final java. lang. Object page = this;

Javax. servlet. jsp. JspWriter _ jspx_out = null;

Javax. servlet. jsp. PageContext _ jspx_page_context = null;

Try {

Response. setContentType ("text/html; charset = UTF-8 ");

PageContext = _ jspxFactory. getPageContext (this, request, response,

Null, true, 8192, true );

_ Jspx_page_context = pageContext;

Application = pageContext. getServletContext ();

Config = pageContext. getServletConfig ();

Session = pageContext. getSession ();

Out = pageContext. getOut ();

_ Jspx_out = out;

Out. write ("\ r \ n ");

Out. write ("\ r \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. write (" \ R \ n ");

Out. write ("JSP\ R \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. print ("hello ");

Out. write ("\ r \ n ");

Out. write ("\ R \ n ");

Out. write ("");

} Catch (java. lang. Throwable t ){

If (! (T instanceof javax. servlet. jsp. SkipPageException )){

Out = _ jspx_out;

If (out! = Null & out. getBufferSize ()! = 0)

Try {out. clearBuffer ();} catch (java. io. IOException e ){}

If (_ jspx_page_context! = Null) _ jspx_page_context.handlePageException (t );

Else throw new ServletException (t );

}

} Finally {

_ JspxFactory. releasePageContext (_ jspx_page_context );

}

}

}

We can see that the JSP file is indeed compiled into a java file on the backend server. We only pay attention to the content we write on the JSP page, but do not pay attention to the parsing of html tags.

// The JSP file will be compiled into a class named index_jsp by the jsp file name (My jsp file name is index. jsp)

Public final class index_jsp extends org. apache. jasper. runtime. HttpJspBase

Implements org. apache. jasper. runtime. JspSourceDependent {

// A parser that generates a JSP file in factory Mode

Private static final javax. servlet. jsp. JspFactory _ jspxFactory =

Javax. servlet. jsp. JspFactory. getdefafactory Factory ();

// Call the initialization method to obtain JSP parameters through global context

Public void _ jspInit (){

_ El_expressionfactory = _ jspxFactory. getJspApplicationContext (getServletConfig (). getServletContext (). getExpressionFactory ();

_ Jsp_instancemanager = org. apache. jasper. runtime. InstanceManagerFactory. getInstanceManager (getServletConfig ());

}

// The thread will be destroyed after compilation.

Public void _ jspDestroy (){

}

// The core is the complete parsing of JSP files.

Response. setContentType ("text/html; charset = UTF-8 ");

PageContext = _ jspxFactory. getPageContext (this, request, response,

Null, true, 8192, true );

_ Jspx_page_context = pageContext;

Application = pageContext. getServletContext ();

Config = pageContext. getServletConfig ();

Session = pageContext. getSession ();

Out = pageContext. getOut ();

_ Jspx_out = out;

// The parsed content

Out. write ("\ r \ n ");

Out. write ("\ r \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. write (" \ R \ n ");

Out. write ("JSP\ R \ n ");

Out. write ("\ R \ n ");

Out. write ("\ R \ n ");

Out. print ("hello ");

Out. write ("\ r \ n ");

Out. write ("\ R \ n ");

Out. write ("");


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.