JAVAWEB:JSP Technology Foundation

Source: Internet
Author: User

Javaweb:jsp Technology Quick Start Introduction
    • JSP full name Java Server pages, is a Dynamic Web development technology . It uses JSP tags to insert Java code into the HTML Web page. labels usually end with <% beginning with%> .
    • JSP is a Java servlet that is primarily used to implement the user interface portion of a Java Web application . Web developers write JSPs by combining HTML code, XHTML code, XML elements, and embedded JSP operations and commands.
    • JSPs get user input data, Access databases, and other data sources through Web Forms, and then dynamically create Web pages .
    • JSP tags have a variety of functions, such as access to the database, record user selection information, access to JavaBeans components, etc., but also in different Web pages to pass control information and share information .
    • JSP technology is in the Java language as a scripting language, JSP Web page for the entire server-side Java Library unit provides an interface to serve the HTTP application.
    • The jsp file suffix is named *.jsp.
    • JSP-developed Web applications can be used across platforms and can run on Linux and on Windows.
First JSP page
JSP processing JSP creation process

The following steps show how a Web server uses JSPs to create a Web page:

    • Just like other normal web pages, your browser sends an HTTP request to the server.

    • The WEB server recognizes that this is a request to a JSP Web page and passes the request to the JSP engine. Complete by using a URL or a. jsp file.

    • The JSP engine loads the JSP files from the disk and translates them into servlets. This conversion simply transforms all template text into a println () statement and translates all of the JSP elements into Java code.

    • The JSP engine compiles the servlet into an executable class and passes the original request to the servlet engine.

    • a component of the WEB server invokes the servlet engine and then loads and executes the servlet class. during execution, the Servlet produces an HTML-formatted output that is embedded in the HTTP response and handed over to the WEB server.

    • The WEB server returns HTTP response to your browser in the form of a static HTML Web page.

    • Eventually, the Web browser handles the dynamically generated HTML page in the HTTP response as if it were working on a static web page.

Legend

  

In a word, JSP and servlet relationship:JSP Web page is another way to write a Servlet without becoming a Java programmer. In addition to the interpretation phase, JSP Web pages can be treated almost as a common Servlet .

JSP life cycle

The key to understanding the underlying functionality of the JSP is to understand the life cycle that they follow. The JSP lifecycle is the entire process from creation to destruction, similar to the servlet life cycle, except that the JSP life cycle also includes compiling the JSP file into a servlet.

Here are a few stages of the JSP life cycle:

Compile phase

When the browser requests a JSP page, the JSP engine first checks to see if the file needs to be compiled. If the file has not been compiled, or has been changed since the last compilation, compile the JSP file.

The compilation process consists of three steps:

    • Parse the JSP file.
    • Convert the JSP file to a servlet.
    • Compile the servlet.
Initialization phase

After the container loads the JSP file, it calls the Jspinit () method before providing any services for the request. If you need to perform a custom JSP initialization task, the Jspinit () method is OK, just like this:

public void Jspinit () {  //Initialize code}

In general, the program is initialized only once, and so is the servlet. Typically, you can initialize a database connection, open a file, and create a query table in the Jspinit () method.

Implementation phase

This phase describes all the interaction of requests in the JSP lifecycle until it is destroyed.

Destruction phase

The destruction phase of the SP life cycle describes everything that happens when a JSP page is removed from the container

JSP Development Basic Syntax

JSP directives

JSP directives are used to set properties related to the entire JSP page, such as the encoding of the Web page and the scripting language .

The syntax format is as follows:

<%@ directive attribute= "value"%>

Directives can have many properties, which exist as key-value pairs and are separated by commas.

Three types of directive tags in JSPs:

instruction Description
<%@ page ...%> Define Web page dependency properties such as scripting language, error page, caching requirements, and more
<%@ include ...%> Include other files
<%@ taglib ...%> Introducing the definition of a tag library
JSP Action Element Description

Unlike JSP directive elements,JSP action elements work in the request processing phase . JSP action elements are written in XML syntax. JSP actions can be used to dynamically insert files, reuse JavaBean components, redirect users to additional pages, and generate HTML code for Java plugins. The action element has only one syntax, which conforms to the XML standard:

<jsp:action_name attribute= "Value"/>

Action elements are basically predefined functions, the JSP specification defines a series of standard actions, which are prefixed with JSP, and the standard action elements available are as follows:

Grammar Description
Jsp:include A file is introduced when the page is requested.
Jsp:usebean Find or instantiate a JavaBean.
Jsp:setproperty Sets the properties of the JavaBean.
Jsp:getproperty Outputs the properties of a JavaBean.
Jsp:forward Move the request to a new page.
Jsp:plugin Generates an object or embed tag for the Java plug-in based on the browser type.
Jsp:element Defining dynamic XML Elements
Jsp:attribute Sets the dynamically defined XML element properties.
Jsp:body Sets the content of a dynamically defined XML element.
Jsp:text Using templates that write text in JSP pages and documents
Demonstrate

JSP simple Application Page refresh automatically

This example uses the Setintheader () method to set the flush header to simulate a digital clock:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><%@ page import=" java.io.*,java.util.* "%>
Click Volume Statistics
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><%@ page import=" java.io.*,java.util.* "%>
Page redirection
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><%@ page import=" java.io.*,java.util.* "%>

 

JAVAWEB:JSP Technology Foundation

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.