JSP Overview JSP (Iava Server Pages) is a dynamic web production technology developed by Sun's Java language that allows you to separate dynamic parts from the web page and static HTML. You can use the usual tools and write an HTML statement in a usual way. Then, the dynamic portion is embedded with a special mark, which often begins with "<%" and ends with "%>". For example, here there is a JSP page:
JSP tutorial title> head> <% out.println ("Hello World");%> i > body> html> It will output "Hello World". Typically, you have to use the file with ".jsp" to extension, and place it to any path where you can place a normal web page. Although the JSP file seems to be a HTML file rather than a servlet file, but in fact, it will convert to a servlet file, where the static HTML is only used to output the information returned by the Servlet service method. If JSP Pages have been converted to servlet and servlet is compiled and loaded (when the first time is request), when you refest this JSP page, it is not perceived. Also pay attention to this phenomenon, some web servers allow you to define an alias for it, as if an URL is a HTML, but in fact it point to a servlet or jsp page, constructed a JSP page, except for embedded Rule HTML, there are three main JSP elements: Scripting Elements, Directives, and Actions. Use Scripting Elements You can define the part of the final conversion to servlet, Directives allows you to control the overall structure of this servlet, and Actions makes you specified Reusable existing components, and also control the operation of the JSP engine. To simplify Scripting Elements, you can take advantage of some predefined variables on a paragraph, such as Request. This taught is explained in JSP's latest version 1.1. Its syntax summarizes the following table, which uses detailed explanation in subsequent courses. Jsp EXPRESSION <% = Expression%> Expression is used to calculate and operate. Expression jsp: Expression>, the predefined variables that can be used include Request, Response, Out, Session, Application, Config, and PageContext (available in SripTlets). JSP Scriptlet <% Code%> Insert the code for the service. code jsp: ScriptleTlet> JSP Declaration The code belonging to the servlet section is not a service method. Code jsp: Declaration> JSP page directive <% @ page att = "val"%> pointing to the path of the servlet engine.
. The following is the legal properties (default bold): l import = "package.class" l contenttype = "mime-type" l isthreadsafe = "true | false "l session =" true | false "l buffer =" sizekb | none "l autoflush =" true | false "l) =" package.class "L info =" message "l errorpage =" URL "L iSerrorPage =" true | false "l language =" Java "JSP include Directive <% @ include file =" URL "%> When the JSP page is translated into servlets, the files on the local system will be included. This URL must be relative. Turn with "JSP: Include Action" when the page is requested. JSP Note <% - Note -%> will be ignored when JSP is converted to servlet. <- Note -> The JSP: Include Action Tune file when the page is requested (Requested). If you want to include the file when the page is translated (Translated), then use the Directive mentioned above. WARNING: On some servers (Servers), the included files can only be HTML or JSP, typically determined by the subscriber name of the file. The JSP: UseBean Action or .... Jsp: usebean> Find or generate a java bean. Possible properties are: L id = " Name "L Scope =" Page | Request | Session | Application "l class =" package.class "l type =" package.class "l beanname =" package.class "the JSP: setProperty action Set the properties of the bean, by clearly specifying or using the parameters obtained by request. Legal attribute: l name = "beanname" l proteth = "protyname | *" l param = "parametername" l value = "val" the JSP: getProperty action Retrieve and output beans properties.