JSP tutorial (1)

zhaozj2021-02-16  47

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> <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 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. <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.</p> <p><jsp: Directive.page att = "val">. 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. <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. The JSP: UseBean Action <JSP: UseBean Att = Val * /> or <JSP: UseBean Att = VAL *> .... </ 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 <jsp: setProperty att = val * /> 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 <jsp: getProperty name = "PropertyName" value = "val" / > Retrieve and output beans properties.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-20429.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="20429" 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.038</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 = 'ZhqGlC3Gc_2Fn_2F6a5DACI5jNOes1fP8F1LCpSqbpQAdQN28yIepMpC2v3JVOrVZHCOYGsdcEjd4KpLD5PI2krLJw_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>