CNET JSP BASIC: Building a JSP web site

Source: Internet
Author: User
Tags format stock prices
Now it's time to put all the JSP syntax together. We will create a Web site with input format for users to enter stock tickers and get the current stock price (about 20 minutes delay). If there is an error, the error page is displayed.

quote.jsp
First, create the quote.jsp with this code and store it in the web directory of the JSWDK installation directory. Most of the content in a Web page is standard HTML format, and JSP code is scattered everywhere. Line 6th is the Web Page Editor guide, which indicates that any errors are routed to the errorpage.jsp file. Lines 13th through 15 are small indicators, basically saying that the table is displayed only if the "symbol" parameter exists. This if section contains code from line 32nd to line 34. Line 17th defines the JavaBean to use, while line 18th loads its symbolic attributes from the argument. Lines 27th through 29 indicate the characteristics of the beans. There is no other Java code except for the IF section.

errorpage.jsp
Next, store the following JSP raw code in the Web page directory of the file errorpage.jsp. This is an error the hint of the page is on the first line, this row sets the page compiler to guide the Iserrorpage property to True. Although the previous page explains where the error page is, this page is saying that it is an error page. The other specific JSP code in the JSP file is the access to the internal exception object. This page only displays its value:

<%@ page iserrorpage= "true"%>

<title>error page</title>
<body>

<!--Print Exception-->
We got ourselves an exception:
<%= Exception%>
<a href= "quote.jsp" >Restart</a>
</body>

Quotes.java
Quotes JavaBean uses Yahoo's resources to get stock prices. The original code needs to be stored in the Quotes.java file in the Classes\com\jguru directory under the JSWDK installation directory. From there, you can use the JSDK compiler to compile it. Once you have built two JSP files, built the JavaBean source and compiled it, you can http://localhost:8080/quote.jsp the quote.jsp file to see the results, assuming you haven't changed JSWDK installation, The use of different ports > this page can be enhanced, but the functionality it renders is a good demonstration of JSP functionality.



Related Article

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.