<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>Stock Quote Struts Application</title>
</head>
<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="68" width="48%">
<div align="left">
<img src="images/stockquote.jpg" alt="Logo">
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<h2>Enter a Stock Symbol</h2>
<!-- Begin Struts form -->
<html:form action="Lookup">
<table width="45%" border="0">
<tr>
<td>Stock Symbol:</td>
<td><html:text property="symbol" /></td>
</tr>
<tr>
<td colspan="2">
<html:submit value="Get Quote" />
</td>
</tr>
</table>
</html:form>
</body>
</html>The purpose of this page is to take the input of a stock symbol from a user and publish a quote for that stock. As you read the code of this jsp file, it looks similar to an HTML page. The difference is in the form and input tags. These tags are struts specific tags. <html:form />.
This <html:form /> is the parent of 2 tags.
The first is the text input tag <html:text />
The second is the SUBMIT tag <html:submit />
The <html:text /> is similar to the HTML text input tag, with the addition of a property attribute which maps to a unique data member in the ActionForm bean class. This data member will be assigned the corresponding text value of the input tag.
<html:text property="symbol" />
When you press SUBMIT on this form, the following actions get performed.- The ActionForm object named by the <html:form /> tag is created and populated with the values in the <html:text /> property field.
- Once the ActionForm is populated with values from the <html:text /> property fields, the Action object referenced by the <html:form /> is invoked and passed a reference to the populated ActionForm.
To use these HTML tags, you must add a taglib library in the application's web.xml file that references the uri /WEB-INF/struts-html.tld.
On the index page once you enter the stock code (In this example it is SUNW), and click on SUBMIT, you will be redirected to the response page quote.jsp. The quote for the same is below.
quote.jsp For more details of the config file changes, you can refer to
Struts config file changes
God's Word for the day
Sample struts-html.tld
Below is a link to a sample struts-html.tld for the current struts version, java version and tomcat version I have used.
Copy this struts-html.tld as is and save it in CATALINA_HOME/webapps/strutsapp/WEB-INF folder as struts-html.tld
Alternately you can give a link to the struts-html.tld from that apache website as below.
Add the below lines in the first 2 lines of index.jsp.
OR
Copy this struts-html.tld file from the lib directory of the extracted Struts archive to the
<CALALINA_HOME>/webapps/strutsapp/WEB-INF folder.
<%@ page language="java" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
A Sample stock quote image
A sample image file to display on the stock quote page is below.
Under CATALINA_HOME/webapps/strutsapp/ folder make a new images folder and place this image in that folder. You can download any stock quote image of your preference from the internet and place it in the mentioned folder path.
References
Hilite.me Code Highlighter
Care in choosing friends
Do not invite everyone into your home,
For many are the tricks of the crafty
Like a decoy partridge in a cage
so is the mind of the proud
And like spies they observe your weakness
For they lie in wait, turning good into evil
And to worthy actions they attach blame.
Sirach 11:29-31
The Law and the prophets
Do not think that I have come to abolish the Law and the prophets
I have come not to abolish but to fulfill
For truly I tell you, until heaven and earth pass away,
not one letter, not one stroke of a letter,
Will pass from the law until all is accomplished.
Therefore, whoever breaks one of the least of these commandments,
And teaches others to do the same, will be called least in the kingdom of heaven;
but whoever does them and teaches them will be called great in the kingdom of heaven
For I tell you, unless your righteousness exceeds that of the scribes and the pharisees
you will never enter the kingdom of heaven.
Mathew 5:17-20

No comments:
Post a Comment