Now it's time to put all the JSP syntaxes together. We will create a website with input format for users to enter the stock code and get the current stock price (about 20 minutes later ). If an error occurs, the error page is displayed.
Quote. jsp
First, use this code to create quote. jsp and store it in the webpage directory of the JSWDK installation directory. Most of the content of a webpage is in standard HTML format, while JSP code is scattered everywhere. Row 3 is a webpage editor guide that instructs you to send any errors to the errorPage. jsp file. Rows from 13th to 15 are small indicator codes. Basically, the table is displayed only when the "symbol" parameter exists. This if segment contains code from lines 32nd to lines 34. The first line defines the JavaBean to be used, and the second line loads its symbolic feature from the parameter. Rows 1 to 29 indicate the properties of beans. Except for the if segment, there is no other Java code.
ErrorPage. jsp
Then, store the following JSP original code to the file errorPage under the webpage directory. jsp. this is the implication of an incorrect webpage in the first line. This line sets the isErrorPage attribute guided by the webpage compiler to true. Although the previous page shows where the error webpage is, this page indicates that it is an error webpage. Other specific JSP code in the JSP file is used to access internal exceptions. This page only displays its values:
<% @ Page isErrorPage = "true" %>
<Html>
<Head>
<Title> Error Page </title>
</Head>
<Body>
<H1> Our Error Page
<! -- Print Exception -->
We got ourselves an exception:
<% = Exception %>
<A href = "quote. jsp"> Restart </a>
</Body>
</Html>.
Quotes. java
Quotes JavaBean uses Yahoo resources to get the stock price. The original code must be stored in the quotes. java file in the classescomjguru directory under the JSWDK installation directory. From there, you can use the JSDK compiler to compile it. Once you have created two JSP files, created the original JavaBean file, and compiled it, you can use http: // localhost: 8080/quote. jsp load quote. the jsp file is used to view the result. If you have not changed the JSWDK installation, you can use different ports> This web page can be enhanced. However, the functions presented by this page are a good example of JSP functions.