JSP Getting Started Primary Tutorial

xiaoxiao2021-03-06  48

JSP Getting Started Primary Tutorial Action

JSP Actions Use you can dynamically insert a file, reuse the JavaBeans component, proceed to another page, or generate an HTML for the Java plugin. The action you can use is: (1) jsp: include - contains a file when the page is requested. (2) JSP: Usebean - find or instantiate a JavaBean. (3) JSP: setProperty - Set a JavaBeaN property. (4) JSP: getProperty - inserts the property of JavaBean into the output. (5) JSP: Forward - Let the requester can go forward to a new page. (6) JSP: Plugin - Generates a specific browser code with the Object or Embed tag to Java Plugins. 1, JSP: Include Action This action allows you to include some files on the upcoming page:

Unlike the include Directive, this action will contain the file when the page is requested, and include Directive is included when the JSP page is converted to servlet. In order to improve efficiency, include Action has a little sacrifice, ie, it does not allow the page included with a general JSP code (for example, it is not available to HTTP header), but it has significant flexibility, as JSP below Code, which implements four different fragments into the page below. Every time you change, you only need to modify these four files without changing the primary JSP page.

Whatsnew.jsp

JSP tutorial </ title> <body> <center> <table border = 5 bgcolor = "# EF8429> <tr> <tr> <Title"> what "s new at Chinese COMIC SITES </ TABLE> </ center> <p> Here is a summary of outness news stories: <ip> <li> <jsp: include page = "news / item1.html" flush = "true" / > <Li> <jsp: include page = "news / item2.html" flush = "true" /> <li> <jsp: include page = "news / item3.html" flush = "true" /> <li> <Jsp: include page = "news / item4.html" flush = "true" /> </ l> </ body> </ html> Of course, you can define yourself? Ml file, but if you pay attention:</p> <p>You should put your files within the news directory in your JSP directory.</p> <p>JSP: Use of UseBean Action</p> <p>First, grammar:</p> <p><Jsp: usebeanid = "beaninstancename" scope = "Page |" {class = "package.class" | type = "package.class" | class = "package.class" type = "package.class" "beanname =" {package.class | <% = expression%>} "type =" package.class "} {/> |> Other elements </ jsp: usebean>}</p> <p>This action allows you to load a JavaBean into a JSP page. This is a very useful ability because it allows you to use reusable Java classes without sacrificing performance. The simplest syntax is used to specify a bean:</p> <p><Jsp: usebean id = "name" class = "package.class" /></p> <p>This usually means "instantiate a class object by specifying a class and will be binded to a variable that is specified by the ID." However, just as we see, you can specify a scope property to make the bean not only contact the current page. In this case, it is very useful to get a reference to the existing bean, and only one new thing is created only when there is no the same ID and Scope beans. Now, you already have a bean, you can modify it via JSP: setProperty, or use the scriptlet or a clear call method by using the name specified by ID. When you say "this bean has a" X-type property called Foo "," You really means "this class has a method called getfoo, it returns a certain value of the X type, and another method is called Setfoo, it is parameter in x. "This JSP: setProperty action will introduce in detail in the next unit, but now you can give a clear value, give a property to indicate that this value is inherited from the parameter from the request. It is also possible to simplify the attribute to mark this value from inheritance from the parameter as the attribute name. You can get existing JSP expressions or scripTlet properties by calling applicable getxxx methods, or more common, using JSP: getProperty Action. Note that the class specified for the bean must be under the classpath of the server's rules, rather than reserved the path of the class that is automatically loaded when changing. For example, on the Java Web Server, it must go to the class directory or in a JAR file in the lib directory, instead of in the directory of servlets. Let us look at a very simple example that loads a bean and sets / get a simple string parameter. Beantest.jsp</p> <p><Head> <title> Reusing JavaBeans in jsp </ title> </ head> <body> <center> <Table Border = 5> <TR> <TH Class = "Title> Reusing JavaBeans in JSP </ Table> < / Center> <p> <jsp: usebean id = "test" class = "hall.simplebean" /> <jsp: setproperty name = "test" property = "message" value = "Hello WWW" /> <h1> message : <I> <jsp: getProperty name = "test" property = "message" /> </ i> </ h1> </ body></p> <p>SimpleBean.java</p> <p>The following is the original code of Bean:</p> <p>package hall; public class SimpleBean {private String message = "No message specified"; public String getMessage () {return (message);} public void setMessage (String message) {this.message = message;}} run results: page Output: Reusing JavaBeans in JSP</p> <p>Message: Hello WWW</p> <p>Second, JSP: Detailed usage of usebean</p> <p>The simplest way of using Bean is:</p> <p><Jsp: usebean id = "name" class = "package.class" /></p> <p>To load beans, you need to modify and retrieve the properties of the bean with JSP: SetProperty and JSP: getProperty. Moreover, there are two other options. First, you can use the format of the container, that is:</p> <p><JSP: Usebean ...> Body </ jsp: usebean></p> <p>It should be pointed out that the Body section should be performed only when Bean is instantiated, not when it is found and used each time. Beans can be shared, so not all JSP: Usebean statements produce a new bean instance. Second, in addition to ID or Class, there are three properties you can use: scope, type, and beanname. These properties summarize as follows:</p> <p>Attribute Meaning ID Names a variable, this variable will point to Bean. If there is a bean having the same ID and Scope, it is not new. Class pointed out the full package of Bean. Scope indicates that the Bean can be used before and after it. There are four possible values: Page, Request, Session, and Application. The default is Page, indicating that the bean is available only in current pages (saved in the current PageContext). A value of Request indicates that the bean is only for the current client request (saved in the servletRequest object). The value of the session pointed out that the object is available for all pages in the current HTTPSession life cycle. Finally, the value of Application pointers that the object can be used on all the shared servletsContext. Use JSP: UseBean creates a new bean only when there is no Same id and scope, if you already use it, and ignore the code that starts and ends with JSP: UseBean flag. TYPE indicates the type of variable that will point to the object. This must match the class name or a superclass or an interface implementation class. Remember, the name of the variable is specified by the id attribute. BeanName gives a name, you should be available in the instantiation method of Beans. It allows you to give Type and a beanName and omitted class properties.</p> <p>Third, JSP: SetProperty Action</p> <p>grammar:</p> <p><Jsp: setPropertyname = "beanInstanceName" {property = "*" | property = "propertyName" [param = "parameterName"] | property = "propertyName" value = "{string | <% = expression%>}"} /> In front of us, we know that you can use JSP: setProperty to assign a value for a bean attribute. You can use two ways to implement it. First, in JSP: UseBean (instead of) use JSP: SetProperty:</p> <p><Jsp: usebean id = "myname" ... />...<jsp:SetProperty name = "myname" property = "someproperty" ... /></p> <p>In this way, JSP: setProperty will be executed whether there is a bean having the same ID and Scope. Alternatively, JSP: setProperty appears within JSP: UseBean Elements, such as:</p> <p><JSP: Usebean ID = "MyName" ...> ... <jsp: setproperty name = "myname" property = "someproperty" ... /> </ jsp: usebean></p> <p>In this case, JSP: SetProperty is only performed when new objects are instantiated.</p> <p>The following is the available properties of four JSP: SetProperty:</p> <p>Attribute Usage Name This is a must-select attribute. It pointed out which bean's attribute will be set. JSP: Usebean must appear before JSP: setProperty. Property This is a must-select attribute. Indicates which property you will set. However, there is a special case: if it is worth "*", all names match the request parameters that match the properties of the bean will be passed to the corresponding attribute setting method. Value This is an optional attribute. It specifies the value of the properties set. The value of the string will be automatically converted to Numbers, Boolean, Boolean, Byte, Byte, Char, and Character by the standard Valueof method of the corresponding object or package. For example, the value of the Boolean or Boolean property will transform through the boolean.valueof method, and the value "42" of an int or Integer property will be converted via Integer.Valueof. You can't use the value and param properties at the same time, but both are allowed. PARAM This is an optional attribute. It indicates the parameters of the Request to be inherited. If the current Request does not have such a parameter, what does not do: the system does not pass NULL to the method of setting the properties. Therefore, you can use the default value of Beans. For example, the following program executes "Set the NumberOfItems property to any NumItems Request parameter, if there is such a request parameter, otherwise, nothing." <Jsp: setproperty name = "Orderbean" Property = "NumberofItems" PARAM = "NumItems" /> If you use Value and Param at the same time, this is the same as the property name that you set the name of the param to the bean. You can set the value of the Request corresponding to the properties of the value and param from "*" and omitted the value of Value and Param. In this case, the server matches the repeated lookup of the available properties and the request parameter to match the same name.</p> <p>Four, JSP: getProperty Action</p> <p>grammar:</p> <p><Jsp: getProperty name = "beaninstancename" property = "printyname" /></p> <p>This property retrieves the value of the property of the bean and convert it into a string, and then insert it into the output. It has two must-select properties: name, the name introduced by JSP: UseBean before, must be inserted attributes.</p> <p>JSP Getting Started Primary Tutorial SESSION</p> <p>The TTP protocol is stateless, that is, the information cannot be passed through the HTTP protocol itself. In order to track the user's operating state, the ASP application session object. JSP uses a object called HTTPSession to achieve the same function. HttpSession is a high quality interface built on cookies and url-rebriting. The SESSION information is saved in the server side, and the session ID is saved in the cookie of the client. In fact, on many servers, if the browser supports them, they use cookies, but if they are not supported or abolished, they are automatically converted to URL-REWRITI, and the session automatically provides convenient storage for each process. Session typically sets a 30-minute expiration time on the server and automatically invalidate after the customer stops the activity. The information saved and retrieved in the session cannot be basic data types such as int, double, etc., but must be Java's corresponding object, such as Integer, Double. HttpSession has the following API: GetId This method returns a unique identifier that is generated for each session. When there is only one single value combined with a session, or when the log information is related to the previous sessions, it is used as a key name. GetCreationTime Returns the time created by Session. The minimum unit is one thousandth. To get a value that is very useful to the printout, this value can be passed to the Date Constructor or Gregoriancalendar's method setTimeinMillis. GetLastAccessedTime returns the time sent by the session. The minimum unit is one thousandth. GetMaxInactiveInterval returns the total time (seconds), and the negative value indicates that the session will never time out. GetaTtribute takes a session information. (In JSP1.0, for getValue) Integer item = (Integer) // Retrieves the value of the session and transforms to integer setAttribute to provide a keyword and a value. Any previous value will be replaced. (Putvalue in JSP1.0) session.setttribute ("itemValue", itemname); // ItemValue must not be a MUST simple type to use the most use of GetAttribute and SetaTRibute. Now use a simple example to illustrate the application of the session, Test1.jsp (Information Write session), Test2.JSP (from the session read information). TEST1.JSP</p> <p><Html> <head> <title> Document </ title> </ head> <body bgcolor = "# ffffff"> session.setttribute ("Str", new string ("this is test"); </ body> </ Html> Test2.jsp <html> <head> <title> new document </ title> </ head> <body bgcolor = "# fff"> <% string ls_str = null; ls_str = (string) session.getattribute ("Str"); Out.println ("The value taken from the session is:" ls_str);%> </ body> </ html> JSP Getting Started Primary Tutorial Taglib Directiv</p> <p>Use the Taglib Directive from the JSP page to define a tag library and prefix. Otimate: <% @ Taglib URI = "Uritotaglibrary" prefix = "tagprefix"%> example: <% @ Taglib URI = "http://www.jspcentral.com/tags" prefix = "public"%> <public: LOOP>. </ public: loop> Description: <% @ taglib%> Indicator (Directive) Allows you to use a custom label, named the label library and specify their prefix. The term Custom TAG is more than just an indicator, but also means an element. Because the JSP file can be converted to XML, it is important to understand the connection between labels and elements. The label is just a flag (Markup), which is part of the JSP element. The JSP element is a JSP syntax unit, which is a start tag and end label in XML. Elements can contain other texts, labels, or elements. For example, a JSP: Plugin element always starts with <JSP: PLUGIN> tag, and it can also contain a <JSP: params> element and <JSP: Fallback> element. You must use a <% @ taglib%> instruction before you use a custom label in a JSP file. You can use multiple <% @ taglib%> instructions in a JSP file, but the prefix defined in each previously defined must be unique. Detailed attributes:</p> <p>URI = "URITOTAGLIBRARY" Unified Resource Definition (URI - The Uniform Resource Identifier) ​​A URI can be the following form: The Uniform Resource LocatoreSource Name). CJSP's use of Plugin's use of Plugin</p> <p>JSP: Plugin Action allows you to insert the Object or Embed element of the required specific browser to specify the plugin required to run a Java Applet. Grammar:</p> <p><Jsp: plugin type = "bean | applet" code = "classfilename" codebase = "classfiledirectoryname" [name = "instancename"] [archive = "uritoarchive, ..."] [align = "bottom | TOP | Middle | LEFT | right "] [height =" displayPixels "] [width =" displayPixels "] [hspace =" leftRightPixels "] [vspace =" topBottomPixels "] [jreversion =" JREVersionNumber | 1.1 "] [nspluginurl =" URLToPlugin "] [iepluginurl = "URLTOPLUGIN"]> [<jsp: params> [<jsp: param name = "parametername" value = "{parameterValue | <% = expression%>}" />] </ jsp: params>] [<JSP : Fallback> Text message for user </ jsp: Fallback>] </ jsp: plugin> Example: <jsp: plugin type = applet code = "molecule.class" codebase = "/ html"> <jsp: params> <JSP : param name = "molecule" value = "molecules / benzene.mol" /> </ jsp: params> <JSP: Fallback> <P> Unable to load applet </ p> </ jsp: Fallback> </ jsp: Plugin></p> <p>Detailed attributes:</p> <p>Attributes</p> <p>usage</p> <p>Type = "bean | applet" plugin will execute the type of object. You must specify one in the bean or applet because this property has no default. The Class = "ClassFileName" plugin will execute the name of the Java class file. You must include extensions in the name. And this file must be in the directory specified by the "CodeBase" property. CodeBase = "classfileDirectoryName" contains the directory of the plugin to run the Java class or point to this directory. The path to this JSP file is default. Name = "InstanceName" bean or the name of the instance of the applet. Communication between beans or Applets called by the same JSP file is possible. Archive = "URLTOARCHIVE, ..." List with a comma-separated path name. It is the path name where the archive file is preloaded by the class loader preloaded in the directory specified by CodeBase. Typically, these archive files are securely loaded through the network, which can significantly improve the performance of the applet. Note and character reference habits You can use some specific elements to insert comments and some characters that are usually as a special logo. The following is a summary: grammar</p> <p>purpose</p> <p><% - Note -%> JSP Form Note. Will be ignored by the jsp-to-scriptlet compiler. Any embedded JSP Scripting Elements, Directives, or Actins will be ignored. Example: <% @ page language = "java"%> <html> <head> <title> a comment test </ title> </ head> <body> <h2> a test of comments </ h2> <% - - This part of the comment will not see the source code -%> </ body> </ html> <! - Note -> HTML form. Directly transferred to the final HTML. Any embedded JSP Scripting Elements, Directives, or Actins will be performed normally. Example: <! - this page was loaded on <% = (New java.util.date ()). TOLOCALESTRING ()%> -> Viewing the source code: <! - this page is loaded ON January 1, 2000 -> </% In Template Text (Static HTML), please write it when you want to output this special symbol (<%) on the page. % /> In Scripting Elements, the role is similar to "</%" above. / 'In the properties of "'", it indicates characters "'". Of course, you can also use "" "as a distinction. Example: 'Pig" fhjgj ", or,' Pig / 'fHjgj /' '/" In the "" "property, it indicates that it is character" "". Of course, you can also use "'" to distinguish. Example: "Pig'fhjgj '", or "Pig /" FHJGJ / ""% /> "%>" in the property. </% "<%" In attributes.</p> <p>JSP Getting Started Primary Tutorial Realization Page Jump</p> <p>JSP uses JSP Forward Action to implement the jump function of the page. Grammar:</p> <p><JSP: Forward Page = "{relativeURL | <% = expression%>}" /> or <jsp: forward point = "{relativeURL | <% = expression%>}"> <jsp: param name = "parametername" Value = "{ParameterValue | <% = expression%>}" /> </ jsp: forward> This action allows you to go to another page forward. It has only one attribute, Page. Page should have a relatively URL composition. This can be a static value or can be calculated when the value is being requested, as two examples below:</p> <p><Jsp: forward page = "/ utils / errorreporter.jsp" /> <jsp: forward page = "<= somejavaExpression%>" />! Supportemptyparas]> Now use a specific example: in Test1.jsp Forward makes it jumps to the Test2.jsp page. TEST1.JSP</p> <p><Html> <head> <title> Forward test </ title>! "@ H>! Supportemptyparas]> <body bgcolor =" # ffffff "> <! - Jump to Test2.jsp -!> <Jsp: forward page = "/ test2.jsp" /> </ body> </ html>! Supportemptyparas]> test2.jsp</p> <p><Html> <head> <title> Forward test </ title>! ("This is the JSP2.jsp page generated by <body bgcolor =" # ffffff "> <% out.println (" this is the JSP2.jsp page Output ");%> </ bo # @ 62; </ html>! Supportemptyparas]> Run Test1.jsp, you can see in the browser:" This is the output information of the JSP2.jsp page " . But what if you have parameter passed in two pages in Test1.jsp and Test2.jsp? With the GET mode, not only the total length is limited, it is very inconvenient to use, and sometimes it is still not safe. In fact, we can completely use the PARA properties provided in Forward in JSP 1.1. Now it is described with Test3.jsp and Test4.jsp.</p> <p>! supportemptyparas]> TEST1.JSP <HTML> <head> <title> forward test </ title>! supportemptyparas]> </ head>! supportemptyparas]> <body bgcolor = "# ffffff"> <jsp: forward page = " / Test4.jsp"> "jsp:Param name = "name" value = "power" /> <jsp: param name = "address" value = "No. 188 Beijing West Street" /> <jsp: Forward> </ Body> </ html>! Supportemptyparas]> TEST2.JSP <html> <head> <title> forward test </ title>! Supportemptyparas]> </ head>! Supportemptyparas]> <body bgcolor = "# ffffff> < % out.println ("This is the output" "<br>") of JSP4.jsp page "); Out.println (" Name: " Request.getParameter (" Name ") " <br> "); Out.println ("Address:" Request.GetParameter ("Address") "<br>") ;! SupportemptyParas]>%> </ body> </ html> Run TEST3.JSP, you can see in the browser Output information: "This is the output of the JSP4.jsp page produced: PowerMan Address: 188 Beijing West Street" "Now in a specific example: use Forward to use Forward to jump to the TEST2.JSP page in Test1.jsp . TEST1.JSP</p> <p><Html> <head> <title> Forward test </ title>! "@ H>! Supportemptyparas]> <body bgcolor =" # ffffff "> <! - Jump to Test2.jsp -!> <Jsp: forward page = "/ TEST2.JSP" /> </ body> </ html>! Supportemptyparas]></p> <p>TEST2.JSP</p> <p><Html> <head> <title> Forward test </ title>! ("This is the JSP2.jsp page generated by <body bgcolor =" # ffffff "> <% out.println (" this is the JSP2.jsp page Output ");%> </ bo # @ 62; </ html>! Supportemptyparas]> Run Test1.jsp, you can see in the browser:" This is the output information of the JSP2.jsp page " . But what if you have parameter passed in two pages in Test1.jsp and Test2.jsp? With the GET mode, not only the total length is limited, it is very inconvenient to use, and sometimes it is still not safe. In fact, we can completely use the PARA properties provided in Forward in JSP 1.1. Now it is described with Test3.jsp and Test4.jsp.</p> <p>! supportemptyparas]> TEST1.JSP <HTML> <head> <title> forward test </ title>! supportemptyparas]> </ head>! supportemptyparas]> <body bgcolor = "# ffffff"> <jsp: forward page = " / Test4.jsp"> "jsp:Param name = "name" value = "power" /> <jsp: param name = "address" value = "No. 188 Beijing West Street" /> <jsp: Forward> </ Body> </ html>! Supportemptyparas]> TEST2.JSP <html> <head> <title> forward test </ title>! Supportemptyparas]> </ head>! Supportemptyparas]> <body bgcolor = "# ffffff> < % out.println ("This is the output" "<br>") of JSP4.jsp page "); Out.println (" Name: " Request.getParameter (" Name ") " <br> "); Out.println ("Address:" Request.getParameter ("Address") "<BR>") ;! SupportemptyParas]>%> </ body> </ html></p> <p>Run Test3.jsp, you can see the output information in your browser</p> <p>: "This is the output of the JSP4.JSP page .: PowerMan Address: No. 188, Beijing West Street</p> <p>JSP Getting Started Primary Tutorial Action</p> <p>JSP Actions Use you can dynamically insert a file, reuse the JavaBeans component, proceed to another page, or generate an HTML for the Java plugin. The action you can use is: (1) jsp: include - contains a file when the page is requested. (2) JSP: Usebean - find or instantiate a JavaBean. (3) JSP: setProperty - Set a JavaBeaN property. (4) JSP: getProperty - inserts the property of JavaBean into the output. (5) JSP: Forward - Let the requester can go forward to a new page. (6) JSP: Plugin - Generates a specific browser code with the Object or Embed tag to Java Plugins. 1, JSP: Include Action This action allows you to include some files on the upcoming page:</p> <p><Jsp: include page = "relative URL" Flush = "true" /> Unlike the include Directive, this action is included when the page is requested, and the include Directive is converted to servlet at the JSP page. Contains files. In order to improve efficiency, include Action has a little sacrifice, ie, it does not allow the page included with a general JSP code (for example, it is not available to HTTP header), but it has significant flexibility, as JSP below Code, which implements four different fragments into the page below. Every time you change, you only need to modify these four files without changing the primary JSP page. Whatsnew.jsp</p> <p><Html> <head> <title> JSP tutorial </ title> <body> <center> <table border = 5 bgcolor = "# EF8429> <tr> <tr> <Title"> what "s new at Chinese COMIC SITES </ TABLE> </ center> <p> Here is a summary of outness news stories: <ip> <li> <jsp: include page = "news / item1.html" flush = "true" / > <Li> <jsp: include page = "news / item2.html" flush = "true" /> <li> <jsp: include page = "news / item3.html" flush = "true" /> <li> <Jsp: include page = "news / item4.html" flush = "true" /> </ l> </ body> </ html> Of course, you can define yourself? Ml file, but if you pay attention: you should The file is placed in the news directory in your JSP directory. JSP: Use of usebean action 1 | type = "package.class" | class = "package.class" type = "package.class" | beanname = "{package.class | <% = expression%>}" type = "package.class"} {/ > |> Other Elements </ jsp: Usebean>} This action allows you to load a JavaBean into a JSP page. This is a very useful ability, because it allows you to use reusable Java classes without sacrificing performance The simplest syntax is used to specify a bean:</p> <p><Jsp: usebean id = "name" class = "package.class" /> This usually means "instantification of a class object by specifying a class and will be bound to a variable bound by ID." However, just as we see, you can specify a scope property to make the bean not only contact the current page. In this case, it is very useful to get a reference to the existing bean, and only one new thing is created only when there is no the same ID and Scope beans. Now, you already have a bean, you can modify it via JSP: setProperty, or use the scriptlet or a clear call method by using the name specified by ID. When you say "this bean has a" X-type property called Foo "," You really means "this class has a method called getfoo, it returns a certain value of the X type, and another method is called Setfoo, it is parameter in x. "This JSP: setProperty action will introduce in detail in the next unit, but now you can give a clear value, give a property to indicate that this value is inherited from the parameter from the request. It is also possible to simplify the attribute to mark this value from inheritance from the parameter as the attribute name. You can get existing JSP expressions or scripTlet properties by calling applicable getxxx methods, or more common, using JSP: getProperty Action. Note that the class specified for the bean must be under the classpath of the server's rules, rather than reserved the path of the class that is automatically loaded when changing. For example, on the Java Web Server, it must go to the class directory or in a JAR file in the lib directory, instead of in the directory of servlets. Let us look at a very simple example that loads a bean and sets / get a simple string parameter. Beantest.jsp <head> <title> Reusing javabeans in jsp </ title> </ head> <body> <center> <table border = 5> <tr> <TH class = "title"> Reusing JavaBeans in jsp </ Table> </ center> <p> <jsp: usebean id = "test" class = "hall.simplebean" /> <jsp: setProperty name = "test" property = "message" value = "Hello WWW" /> < H1> Message: <i> <jsp: getproperty name = "test" property = "message" /> </ i> </ h1> </ body> SimpleBean.java The following is the original code of Bean:</p> <p>package hall; public class SimpleBean {private String message = "No message specified"; public String getMessage () {return (message);} public void setMessage (String message) {this.message = message;}} run results: page Output: Reusing JavaBeans in JSP Message: Hello WWW II, JSP: User's Detailed Usage The simplest use of bean is: <jsp: usebean id = "name" class = "package.class" /></p> <p>To load beans, you need to modify and retrieve the properties of the bean with JSP: SetProperty and JSP: getProperty. Moreover, there are two other options. First, you can use the format of the container, that is:</p> <p><JSP: Usebean ...> Body </ jsp: usebean></p> <p>It should be pointed out that the Body section should be performed only when Bean is instantiated, not when it is found and used each time. Beans can be shared, so not all JSP: Usebean statements produce a new bean instance. Second, in addition to ID or Class, there are three properties you can use: scope, type, and beanname. These properties summarize as follows:</p> <p>Attribute Meaning ID Names a variable, this variable will point to Bean. If there is a bean having the same ID and Scope, it is not new. Class pointed out the full package of Bean. Scope indicates that the Bean can be used before and after it. There are four possible values: Page, Request, Session, and Application. The default is Page, indicating that the bean is available only in current pages (saved in the current PageContext). A value of Request indicates that the bean is only for the current client request (saved in the servletRequest object). The value of the session pointed out that the object is available for all pages in the current HTTPSession life cycle. Finally, the value of Application pointers that the object can be used on all the shared servletsContext. Use JSP: UseBean creates a new bean only when there is no Same id and scope, if you already use it, and ignore the code that starts and ends with JSP: UseBean flag. TYPE indicates the type of variable that will point to the object. This must match the class name or a superclass or an interface implementation class. Remember, the name of the variable is specified by the id attribute. BeanName gives a name, you should be available in the instantiation method of Beans. It allows you to give Type and a beanName and omitted class properties.</p> <p>Third, JSP: SetProperty Action Syntax:</p> <p><Jsp: setPropertyname = "beanInstanceName" {property = "*" | property = "propertyName" [param = "parameterName"] | property = "propertyName" value = "{string | <% = expression%>}"} /> In front of us, we know that you can use JSP: setProperty to assign a value for a bean attribute. You can use two ways to implement it. First, in JSP: Usebean (instead of) use JSP: setProperty: <JSP: usebean id = "myname" ... /> ... "" " SomeProperty "... /> In this manner, JSP: setProperty will be executed whether there is a bean with the same ID and Scope. Alternatively, JSP: setProperty appears within JSP: UseBean Elements, such as:</p> <p><Jsp: usebean id = "myname" ...> ... <jsp: setproperty name = "myname" property = "someproperty" ... /> </ jsp: usebean> JSP: setProperty only The new object is actually executed. The following is the available properties of four JSP: SetProperty:</p> <p>Attribute Usage Name This is a must-select attribute. It pointed out which bean's attribute will be set. JSP: Usebean must appear before JSP: setProperty. Property This is a must-select attribute. Indicates which property you will set. However, there is a special case: if it is worth "*", all names match the request parameters that match the properties of the bean will be passed to the corresponding attribute setting method. Value This is an optional attribute. It specifies the value of the properties set. The value of the string will be automatically converted to Numbers, Boolean, Boolean, Byte, Byte, Char, and Character by the standard Valueof method of the corresponding object or package. For example, the value of the Boolean or Boolean property will transform through the boolean.valueof method, and the value "42" of an int or Integer property will be converted via Integer.Valueof. You can't use the value and param properties at the same time, but both are allowed. PARAM This is an optional attribute. It indicates the parameters of the Request to be inherited. If the current Request does not have such a parameter, what does not do: the system does not pass NULL to the method of setting the properties. Therefore, you can use the default value of Beans. For example, the following program executes "Set the NumberOfItems property to any NumItems Request parameter, if there is such a request parameter, otherwise, nothing." <Jsp: setproperty name = "Orderbean" Property = "NumberofItems" PARAM = "NumItems" /> If you use Value and Param at the same time, this is the same as the property name that you set the name of the param to the bean. You can set the value of the Request corresponding to the properties of the value and param from "*" and omitted the value of Value and Param. In this case, the server matches the repeated lookup of the available properties and the request parameter to match the same name. Fourth, JSP: getProperty Action Syntax: <jsp: getproperty name = "beaninstancename" property = "protyname" /> This property retrieves the value of the bean's attribute and convert it into a string, and then insert it into the output. It has two must-select properties: name, the name introduced by JSP: UseBean before, must be inserted attributes.</p> <p>The use of the predefined variable of JSP entry primary tutorial</p> <p>The JSP expression and the code in Scriptlets provide 8 automatic defined variables, sometimes called Implicit Objects. They are: Request, Response, Out, Session, Application, Config, PageContext, and Page. Let's take a detailed understanding of them. Request is associated with Request's HTTPSERVLETREQUEST class so that you can get Request's parameters (via getParameter method), Request's type (GET, Post, Head, etc.), and introduced HTTP heads (cookies, refrer, etc.) . Strictly speaking, Request is a subclass of class servletRequest rather than HTTPSERVLETREQUEST classes, in fact, if the Request's protocol is not HTTP, then it hardly works. Response is connected to the client's Response with HttpservletResponse. Note that because the output stream is placed in buffer, the HTTP status code and the response head can be set, although it is not allowed to send it to the client in the standard servlets. OUT This uses the PrintWriter class to send output to the client. However, in order to enable the Response object, you can use the use of a PRINTWRITE class using buffer version JSpWriter. Using the properties of the session page Directive, you can define the size of the buffer, or even shut down the buffer after using the buffer property. Please also note that OUT is only used in ScriptleTs because the JSP expression is automatically placed in output stream, so you need a little declaration of OUT. The Session application is associated with the Request. Because Session is automatically created, this variable can still be bound even if there is no introduced session. There is an exception that if you use the Page Directive to close the session, you will cause an error when you try to use the Session (when the JSP page is converted to servlet). Application uses the ServeTContext class to get by using getServletConfig (). GetContext (). Config is an object of a ServletConfig class. PageContext This is a new class PageContext in JSP, uses when practicing the characteristics of a particular server, such as increasing the efficiency of JSPWriters. If you pass this class, your code will still run in the "Rule" JSP / Servlet Engine BR> Page is not very useful in Java, it is just the language used to save on the script is not Java. time. JSP Getting Started Primary Tutorial <JSP Directive Mso-Hansi-Font-Family: "> The overall structure of the Servlet class <JSP Directive Mso-Hansi-font-Family:"> Impacts the overall structure of the servlet class. It often uses the following form:</p> <p><% @ Directive Attribute = "Value"%> And you can write multiple properties in a statement:</p> <p><% @ Directive Attribute1 = "Value1" Attribute2 = "Value2" attributen = "VALUEN"%> There are two main Directive: Page, allowing you to do some things like Import Classes, define the superclass, MSO -Hansi-Font-Family: ""> Include, allow you to insert files into the servlet class (when JSP file is translated into servlet). I. JSP Page Directive Syntax: <% @ Page [Language = "Java"] [EXTENDS = "Package .class"] [import = "{package .class |. *}, ..."] [session = "true | false "] [buffer =" none | 8kb | sizekb "] [autoflush =" true | false "] [isthreadsafe =" true | false "] [info =" text "] [errorpage =" relativeURL "] [contenttype = "MIMETYPE [; Charset = Characterset] |" Text / HTML; Charset = ISO-8859-1 "] [iSerrorPage =" true | false "]%> Page Directive MSO-Hansi-font-family:"> Allow you Define some properties of case-sensitive: (1) Import = "package.class" or import = "package.class1, .., package.classn". MSO-Hansi-Font-Family: ""> You can try your IMPORT package. E.g:</p> <p><% @ Page import = "java.util. *"%> IMPORT attribute is the only one in these properties that can occur multiple times in one JSP. (2) ContentYPE = "MIME = Type" or contenttype = "MIME-TYPE; CHARSET = Character-SET" MSO-HANSI-FONT-FAMILY: "> It specifies the output MIME type. The default is "Text / HTML". E.g:</p> <p><% @ Page ContentType = "Text / Plain"%> "in Scriptlet Medium price:</p> <p><% Response.setContentType ("text / plain");%> (3) isthreadsafe = "true | false". If the value is "true" (the default) indicates that ordinary servlet processing, multiple requests will be A servlet instance is parallel, in which case the programmer is synchronized to access multiple instance variables. When the value is "false", it means that the servlet will implement single-threaded modhmodel, regardless of whether the request is sequential or concurrent, and will provide different separation servlet instances. (4) Session = "True | FALSE". If the value is "true" (default) indicates that the predefined variable session should be bound to an existing session, otherwise it should be created and bind it. When the value is "false", it means: If the session variable will not be used, if you try to use, an error will occur when the JSP is converted to servlet. (5) Buffer = "sizekb | none". Output the size of the buffer to the JSPWriter. The default is determined by the server, but at least 8KB. (6) Autoflush = "True | FALSE". If the value is "True Mso-Hansi-Font-Family:"> "(default) indicates that it will be automatically emptied when it is buffered, the value is" false mso-hansi-font-family: ">" means: ">" Exercise an exception when it is built, which is rarely used. When buffer = "none" is not legal if you use false mso-hansi-font-family: "">. (7) Extends = "package.class". This will create a superclass for the servlet. Please use this feature special carefully because the server may have defined one. (8) Info = "message". Define a string that can be obtained by calling the GetServletInfo method. (9) ErrorPage = "URL". Specify a JSP MSO-Hansi-Font-Family: "" page to handle any accidental errors that can be thrown but the current page is not processed. (10) iSerrorPage = "True | FALSE". Specifies whether the current page can handle errors from another page, default is "false". (11) Language = "Java" MSO-Hansi-font-family: "">. It is pointed out the language below will be used. However, it is not necessary for this property, because "Java Mso-Hansi-Font-Family:"> "is the only legal choice for the default. Two JSP Include Directive This Directive allows you to include a file when JSP is converted to servlet. grammar:</p> <p><JSP: Include Page = "{RelativeURL | <% = Expression%>}" Flush = "true" /> mso-hansi-font-family: "; mso-font-kerning: 0pt"> or <JSP: include Page = "{relativeurl | <% = expression%>}" Flush = "true"> <jsp: param name = "parameters" value = "{parameter" value | <% = expression%>} "/> </ jsp: incrude > URL MSO-HANSI-FONT-FAMILY: ""> It is usually relative to its JSP page, however, the relative "URL" is commonly used, you can use a slash "/" as the beginning of the URL to inform the system URL MSO- Hansi-font-family: ""> The main path of the relative web server. The file being included will be parsed in a rule of JSP, so you can use static HTML, Scripting Elements, Directives, and Actions. Let's take an example, and many sites contain a small navigation bar on each page. It usually appears on the top or left and right side of the page and is included in each page. This is very natural with include Directive. If you use the rule of HTML MSO-HANSI-FONT-FAMILY: "", it is undoubtedly a dream. Please see the following code: <html> <head> <title> JSP tutorial </ title> </ head> <body> <% @ @ @ @ @ @@@@% = = "/ navbar.html"%> <! - This page is available. .. -> </ body> </ html> Because the file is inserted when the page is converted, so if the navigation bar changes, you need to put all the JSP MSO-Hansi-font-family: "" " > The page is all recompiled once. If your navigation bar does not often change this, it is undoubtedly efficient, but if your containment file changes frequently, it is recommended that you use JSP: Include Action to replace it, it is requested at the page. Only the file is included.</p> <p><% @ Directive Attribute = "Value"%> And you can write multiple properties in a statement:</p> <p><% @ Directive Attribute1 = "Value1" Attribute2 = "Value2" attributen = "VALUEN"%> There are two main Directive: Page, allowing you to do some things like Import Classes, define the superclass, MSO -Hansi-Font-Family: ""> Include, allow you to insert files into the servlet class (when JSP file is translated into servlet). I. JSP Page Directive Syntax: <% @ Page [Language = "Java"] [EXTENDS = "Package .class"] [import = "{package .class |. *}, ..."] [session = "true | false "] [buffer =" none | 8kb | sizekb "] [autoflush =" true | false "] [isthreadsafe =" true | false "] [info =" text "] [errorpage =" relativeURL "] [contenttype = "MIMETYPE [; Charset = Characterset] |" Text / HTML; Charset = ISO-8859-1 "] [iSerrorPage =" true | false "]%> Page Directive MSO-Hansi-font-family:"> Allow you Define some properties of case-sensitive: (1) Import = "package.class" or import = "package.class1, .., package.classn". MSO-Hansi-Font-Family: ""> You can try your IMPORT package. E.g:</p> <p><% @ Page import = "java.util. *"%> IMPORT attribute is the only one in these properties that can occur multiple times in one JSP. (2) ContentYPE = "MIME = Type" or contenttype = "MIME-TYPE; CHARSET = Character-SET" MSO-HANSI-FONT-FAMILY: "> It specifies the output MIME type. The default is "Text / HTML". E.g:</p> <p><% @ Page ContentType = "Text / Plain"%> "in Scriptlet Medium price:</p> <p><% Response.setContentType ("text / plain");%> (3) isthreadsafe = "true | false". If the value is "true" (the default) indicates that ordinary servlet processing, multiple requests will be A servlet instance is parallel, in which case the programmer is synchronized to access multiple instance variables. When the value is "false", it means that the servlet will implement single-threaded modhmodel, regardless of whether the request is sequential or concurrent, and will provide different separation servlet instances. (4) Session = "True | FALSE". If the value is "true" (default) indicates that the predefined variable session should be bound to an existing session, otherwise it should be created and bind it. When the value is "false", it means: If the session variable will not be used, if you try to use, an error will occur when the JSP is converted to servlet. (5) Buffer = "sizekb | none". Output the size of the buffer to the JSPWriter. The default is determined by the server, but at least 8KB. (6) Autoflush = "True | FALSE". If the value is "True Mso-Hansi-Font-Family:"> "(default) indicates that it will be automatically emptied when it is buffered, the value is" false mso-hansi-font-family: ">" means: ">" Exercise an exception when it is built, which is rarely used. When buffer = "none" is not legal if you use false mso-hansi-font-family: "">. (7) Extends = "package.class". This will create a superclass for the servlet. Please use this feature special carefully because the server may have defined one. (8) Info = "message". Define a string that can be obtained by calling the GetServletInfo method. (9) ErrorPage = "URL". Specify a JSP MSO-Hansi-Font-Family: "" page to handle any accidental errors that can be thrown but the current page is not processed. (10) iSerrorPage = "True | FALSE". Specifies whether the current page can handle errors from another page, default is "false". (11) Language = "Java" MSO-Hansi-font-family: "">. It is pointed out the language below will be used. However, it is not necessary for this property, because "Java Mso-Hansi-Font-Family:"> "is the only legal choice for the default. Two JSP Include Directive This Directive allows you to include a file when JSP is converted to servlet. grammar:</p> <p><JSP: Include Page = "{RelativeURL | <% = Expression%>}" Flush = "true" /> mso-hansi-font-family: "; mso-font-kerning: 0pt"> or <JSP: include Page = "{relativeurl | <% = expression%>}" Flush = "true"> <jsp: param name = "parameters" value = "{parameter" value | <% = expression%>} "/> </ jsp: incrude > URL MSO-HANSI-FONT-FAMILY: ""> It is usually relative to its JSP page, however, the relative "URL" is commonly used, you can use a slash "/" as the beginning of the URL to inform the system URL MSO- Hansi-font-family: ""> The main path of the relative web server. The file being included will be parsed in a rule of JSP, so you can use static HTML, Scripting Elements, Directives, and Actions. Let's take an example, and many sites contain a small navigation bar on each page. It usually appears on the top or left and right side of the page and is included in each page. This is very natural with include Directive. If you use the rule of HTML MSO-HANSI-FONT-FAMILY: "", it is undoubtedly a dream. Please see the following code:</p> <p><Html> <head> <title> JSP tutorial </ title> </ head> <body> <% @ include file = "/ navbar.html"%> <! - Distinguished section of this page ... -> </ Body> </ html> Because the file is inserted when the page is converted, therefore, if the navigation bar changes, you need to re-compile all the JSP MSO-Hansi-font-family: ""> page points to it. once. If your navigation bar does not often change this, it is undoubtedly efficient, but if your containment file changes frequently, it is recommended that you use JSP: Include Action to replace it, it is requested at the page. Only the file is included. JSP Barter Tutorial 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: <html> <head> <title> JSP tutorial </ title> </ head> <body> <i> <% 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 teaching program is explained in JSP1.1.</p> <p>Its syntax summarizes the following table, which uses detailed explanation in subsequent courses. Jsp EXPRESSION <% = Expression%> Expression is used to calculate and operate. <JSP: Expression> 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. <JSP: Scriptlet> code </ jsp: ScriptleTlet> JSP Declaration <!% Code%> The code belonging to the servlet section is not a service method. <JSP: Declaration> Code </ jsp: Declaration> JSP page directive <% @ page att = "val"%> pointing to the path of the servlet engine. <JSP: Directive.page Att = "VAL" />. The following is the legal properties (default bold): import = "package.class" ContentType = "mime-type" isthreadsafe = "true | false" session = "True | false" buffer = "sizekb | none" autoflush = "true | false" extends = "package.class" info = "message" errorpage = "url" iesrrorpage = "true | false" 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. <JSP: Directive.include File = "URL" /> 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 <JSP: Include Page = "Relative URL" flush = "true" /> 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.</p> <p>The JSP: UseBean Action <JSP: UseBean Att = Val * /> or <JSP: UseBean Att = VAL *> .... </ Jsp: Usebean> Looking for or generating a java bean. Possible properties are: ID = "name "Scope =" Page | Request | Session | Application "class =" package.class "type =" package.class "beanname =" package.class "the JSP: setProperty action <jsp: setProperty att = val * /> set bean Attributes, by clearly specifying or using the parameters obtained by request. Legal attribute: name = "beanname" proty = "preordyname | *" param = "parametername" value = "val" the JSP: getProperty action <jsp: getproperty name = "protyname" value = "val" /> retrieved and output Bean's properties. The JSP: Forward Action <JSP: Forward Page = "RELATIVE URL" /> Another page. The JSP: PLUGIN Action <JSP: Plugin Attribute = "Value" *> </ jsp: Plugin> Generates a specific browser Object or an Embed tab to explicitly run the Java plugin used in Applet. Commonly used five combinations WinKey D:</p> <p>This is the most commonly used first quick combination key of the master. This shortcut combination can instantly minimize all windows on the desktop, whether the chat window is or the window of the game ... Just press this combination key again, all the windows just have come back, and activated is your smallest. Before using the window!</p> <p>WinKey f:</p> <p>No need to move the mouse point "Start → Search → Files and Folders", in any state, just pressing WinKey F, the search window will pop up.</p> <p>WINKEY R:</p> <p>In our article, you often see such actions: "Click 'Start → Run', open the 'Run' dialog ...". In fact, there is a simpler way, that is, press WINKEY R!</p> <p>Alt Tab:</p> <p>If the window is opened, this key button is very useful, it can display the name and icon of all the windows currently open in a window ●, select the window you want to open, and release this combination key. The ALT TAB SHIFT key can reverse the currently open window.</p> <p>WinKey E:</p> <p>When you need to open the resource manager to find a file, this shortcut will make you feel very "cool"! Never use one hand to touch the mouse!</p> <p>hint:</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-45224.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="45224" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.054</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'WKMZx9ONDxhJIiBdSBsh4WpaNvgeIhWcURl7Fkwl3w8Xlotg15_2FlUVEt_2Bij0Ykm7AKGNf3QDQtBDnajvSfgWGQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>