The essential difference between scripts, declarations, and expressions in JSPs

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:18px"><span style="font-size:18px">Original Address:</span> <span style="font-size:18px">http://blog.csdn.net/csuliky/article/details/2444854</span></span></p></p><span style="font-size:18px"><span style="font-size:18px"> <span style="color:#ff0000">JSP scripting elements</span> </span></span><p><p><span style="font-size:18px">Using JSP scripting elements, You can embed Java code in a JSP page that will appear in the servlet generated by the current JSP Page.</span></p></p><p><p><span style="font-size:18px">enables JSPs to separate static content from dynamic Content. The script element package</span> <span style="font-size:18px">contains:</span></p></p><span style="font-size:18px"><span style="font-size:18px"> <span style="color:#ff0000">1. Expressions</span> </span></span><p><p><span style="font-size:18px">Expression: is the representation of the data, which the system calculates as a Value.</span></p></p><p><p><span style="font-size:18px">Syntax: <%= expression%></span></p></p><p><p><span style="font-size:18px">Example: <%=user.getname ()%></span></p></p><p><p><span style="font-size:18px">The essence of an expression: after converting a JSP page into a servlet, use out.print () to output the value of the Expression. If the return of User.getname ()</span></p></p><p><p><span style="font-size:18px">Return value is "liky", then in fact in the servlet will be converted to Out.print ("liky");</span></p></p><span style="font-size:18px"><span style="font-size:18px">So here are the two points to note:<br></span></span><p><p><span style="font-size:18px">1) If the expression is to invoke a method, then this method must have a return value instead of void, that is, void GetName ()</span></p></p><p><p><span style="font-size:18px">Method is not Callable.</span></p></p><p><p><span style="font-size:18px">2) there can be no semicolon after the method, for example <%=getname ();%> this is not allowed.</span></p></p><span style="font-size:18px"><span style="font-size:18px"> <span style="color:#ff0000">2. Scripts</span> </span></span><p><p><span style="font-size:18px">Script: is embedded in <%%> java code, here Java code and our general Java code is no different, so each statement</span></p></p><p><p><span style="font-size:18px">The same should be ";" The end, which is not the same as the expression</span></p></p><p><p><span style="font-size:18px">syntax:% code%></span></p></p><p><p><span style="font-size:18px">The nature of the script is to insert the code into the Servlet's service () method.</span></p></p><p><p><span style="font-size:18px">For example:</span></p></p><p><p><span style="font-size:18px"></span></p></p><pre code_snippet_id="1752590" snippet_file_name="blog_20160708_1_4183778" name="code" class="plain"><pre code_snippet_id="1752590" snippet_file_name="blog_20160708_1_4183778" name="code" class="plain"><% If (user! = Null) { %> Hello <B><%=user%></B> <% } Else { %> You haven ' t login! <% } %></pre></pre><p><p></p></p><p><p><span style="font-size:18px">Translated Into:</span></p></p><p><p><span style="font-size:18px"></span></p></p><pre code_snippet_id="1752590" snippet_file_name="blog_20160708_2_4151541" name="code" class="plain"><pre code_snippet_id="1752590" snippet_file_name="blog_20160708_2_4151541" name="code" class="plain">If (user! = Null) { out.println ("Hello <B>" + user + "</B>"); } else { out.println ("you haven ' t l ogin! "); }</pre></pre><p><p></p></p><span style="font-size:18px"><span style="font-size:18px"> <span style="color:#ff0000">3. Disclaimer</span> </span></span><span style="font-size:18px"><span style="font-size:18px">Declaration: is to allow the user to define variables, methods in the Servlet.<br></span></span><p><p><span style="font-size:18px">Syntax: <%! code%> for Example: <%! String getName () {return name;}%></span></p></p><p><p><span style="font-size:18px">The essence of the declaration is that the method of adding the declared variable to the servlet class (outside of any METHOD) is the servlet () Approach.</span></p></p><p><p><span style="font-size:18px"><br></span></p></p><span style="font-size:18px"><span style="font-size:18px"> <br></span></span><p><p>The essential difference between scripts, declarations, and expressions in JSPs</p></p></span>

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.