JSP Getting Started Tutorial (4) _ MySQL

Source: Internet
Author: User
Using scripts in some places, you may add some good and mature programs to your JSP page. although JSP labels are powerful, however, it is difficult to complete some work. In this case, you can use the script language segment to add JSP labels. The JSP Engine used supports the scripting language. for details about SUN's JSP reference, you must use the Java programming language to compile the script.
In some places, you may add some good and mature programs to your JSP page. although JSP labels are powerful, it is difficult to complete some work. In this case, you can use the script language segment to add JSP labels.
The JSP Engine used supports the scripting language. for SUN's JSP reference, you must use the Java programming language to compile the script, however, other third-party JSP engines allow scripting in other languages.
How to add scripts
First, you must understand some basic rules for adding script elements to JSP pages.
1. use the Page command to define the script on the JSP Page (the default value is Java, which is generally not required)
2. declaration syntax <% !...... %> Declare variables and methods (functions ).
3. expression syntax <% = ...... %> Define a script language expression
4. script syntax <% ...... %> Operation declaration, expressions, and other types of valid code segments can be performed in the page scripting language.
5. add %> tag at the end
Declarations, expressions, and scripts are similar, but there are also some differences. let's use some examples to illustrate the similarities and differences.
Statement <% !...... %> Contains one or more variables and methods separated by semicolons.

Example: <%! Int I = 0; %>
<%! Int a, B; double c; %>
<%! Circle a = new circle (2.0); %>
Before using variables and methods on the page, you must declare
The declared range is usually a JSP page, but if the page uses the INCLUDE command to INCLUDE other pages, the range strain can be extended to the included page.
Expression <% = ...... %> You can include any legal language expressions on the page without semicolons.
Example: <% = Math. sqrt (2) %>
<% = Item [I] %>
<% = A + B + c %>
<% = New java. util. date () %>
A key difference between an expression and a script is that a semicolon is not required. If you need to use an expression in the script, you must add a plus sign.
Script <% ...... %> Any number of scripting languages you can write
Example: <% String name = null;
If (request. getParmeter ("name") = null {
%>
Remember to end with a semicolon in the script.
Guess digital games
It is very interesting to guess digital games, and you can also learn a lot about expression usage from here.
Code
Display the main screen (numguess. jsp)

<% @ Page import = "num. NumberGuessBean" %>





Number Guess



<% If (numguess. getSuccess () {%>

Congratulations! You got it.
And after just <% = numguess. getNumGuesses () %> tries.



<% Numguess. reset (); %>
Care to try again?

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.