J2EE 13 specification (4)-JSP

Source: Internet
Author: User

J2EE 13 specification (4)-JSP

JSP is also called a Java Server Page. See If jsp immediately thought of asp that was previously learned.

I. Comparison between jsp and asp:

JSP (Java Server Page) and ASP (Active Server Page) are both common dynamic web pages and can be embedded into HTML programs. However, they are essentially different, it is compared in the following aspects:
1. Web Server support: most common Web servers, such as Apache, Netscape, and Microsoft IIS, support JSP pages. Only Microsoft IIS and Personal Web Server support ASP.
2. platform support: JSP is platform independent. As long as it is a platform where general Java programs can run, JSP programs are supported. The Windows platform can support ASP well, but the dependency of ASP on Win32-based models makes it difficult to transplant to other platforms.
3. scripting language: JSP can use Java programming language or JavaScript as the scripting language, while ASP uses VBScript or Jscript as the scripting language.
4. Security: JSP uses the Java security model, while ASP uses the security structure of Windows NT.

In fact, with our in-depth study of jsp, we found that JSP is closely related to servlet. Like Servlet, JSP is executed on the server. Generally, an HTML text is returned to the client. Therefore, the client can be viewed by a browser .. JSP technology uses Java programming language to compile tags and scriptlets like XML to encapsulate the processing logic for generating dynamic web pages. The web page can also access the application logic of resources on the server through tags and scriptlets. JSP separates the Web page logic from the display of the Web page design. It supports Reusable Component-based design, making Web-based application development fast and easy. JSP is a dynamic page technology. Its main purpose is to separate the presentation logic from the Servlet.

Ii. Differences between JSP and servlet:

1. No built-in objects exist in the Servlet. Originally, all the built-in objects in Jsp must be generated through the HttpServletRequest object or the HttpServletResponse object.
2. for Static HTML tags, the Servlet must use the webpage output stream for the response line output.

3. jsp is eventually compiled into servlet, so jsp is slower than servlet. Jsp is responsible for front-end page display, and servlet is responsible for business control.

In short, Jsp is a simplification of Servlet. To use Jsp, you only need to complete the content that the programmer needs to output to the client. As for how to embed Java scripts in Jsp into a class, it is done by the Jsp Container. Servlet is a complete Java class. The Service method of this class is used to generate a response to the client.

Iii. Simple instances

1. HTML client code:

 HelloWorld <%out.println("HelloWorld");%>
2. jsp is working. In the tomcat work folder, the following java and response class file code will be automatically generated:

package org.apache.jsp;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;public final class HelloWorld_aaa extends org.apache.jasper.runtime.HttpJspBase    implements org.apache.jasper.runtime.JspSourceDependent {  private static java.util.List _jspx_dependants;  public Object getDependants() {    return _jspx_dependants;  }  public void _jspService(HttpServletRequest request, HttpServletResponse response)        throws java.io.IOException, ServletException {    JspFactory _jspxFactory = null;    PageContext pageContext = null;    HttpSession session = null;    ServletContext application = null;    ServletConfig config = null;    JspWriter out = null;    Object page = this;    JspWriter _jspx_out = null;    PageContext _jspx_page_context = null;    try {      _jspxFactory = JspFactory.getDefaultFactory();      response.setContentType("text/html");      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("\t\r\n");      out.write("\t\tHelloWorld\r\n");      out.write("\t\r\n");      out.write("\t\r\n");      out.write("\t\t");out.println("HelloWorld");      out.write("\r\n");      out.write("\t\r\n");      out.write("");    } catch (Throwable t) {      if (!(t instanceof SkipPageException)){        out = _jspx_out;        if (out != null && out.getBufferSize() != 0)          out.clearBuffer();        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);      }    } finally {      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);    }  }}
Jsp, asp, and servlet are compared to learning, so we can gradually understand the truth.

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.