Java Tutorial - Java Script :
You also can use Java statements in JSP—calling methods, assigning values to variables, creating conditional statements, and so on. These statements begin with the <% tag and end with the %> tag. More than one statement can be enclosed within these tags. Statements that appear inside a page are called scriptlets. You can use any of the servlet variables that were available for expressions. Listing 21.6 contains the code for shop-for-books.jsp, a web page that displays a list of books, with hyperlinks to each book’s page at an online bookstore.
This page includes a form at the bottom of the page that lets users choose which bookstore they like to use for online shopping. In line 29, the form is being submitted to the URL of the page. Because pages are actually servlets, they can also receive form data that’s sent by post or get. This page uses the store field to hold “Amazon” if Amazon.com is the preferred store and “BN” if Barnes & Noble is the preferred store. One thing to note as you test the page is how the radio buttons on the form always match the store you’ve chosen. This occurs because of expressions that appear on lines 29 and 31. Here’s one of those expressions:
<%= (store.equals(“Amazon”) ? “ checked” : “”) %>
This expression uses the ternary operator with the conditional store.equals(“Amazon”). If this condition is true, the word “checked” is the value of the expression. Otherwise, an empty string (“”) is the value. The value of expressions is displayed as part of the JSP page. Figure 21.6 shows what this page looks like in a web browser.