I'm trying to teach myself JSP and create something for my portfolio.
I decided to set up a prototype for an "Alternative" on-line bookstore.
Here's the code for an "Item Page"
Code:
<%@page contentType="text/html"%>
<html>
<head>
<style>
<!--Style Sheet-->
</style>
<title>Islam A Short History</title>
</head>
<body>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
<table width='640'>
<tr>
<td width='640' colspan='2'>
<h1 align='center'>The People's Bookstore</h1>
</td>
</tr>
<tr>
<td width='640' colspan='2'>
<h2 align='center'>Knowledge Is Power</h2>
</td>
</tr>
<tr>
<td width='100'>
<IMG src='./Images/Islam.gif' alt='Islam--A Short History'>
</td>
<td width='540'>
<!--May become a review or suggestion area-->
</td>
</tr>
<tr>
<td width='640' colspan='2'>
<form action='./processOrder_DEBUG.jsp' method='get'>
<input type='hidden' name='title' value='Islam--A Short History'>
<b>Islam--A Short History<br>
Karen Armstrong</b>
<br>
<b>Price:</b> <input type='text' name='price' maxlength='7' value="$19.95"
readonly>
<!--For the price, may need to do some funny programming here-->
<input type='hidden' name='cost' value='19.95'>
<br>
<b>Amount:</b>
<select name='quantity'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3.'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
</td>
</tr>
<tr>
<td width='640' colspan='2'>
<input type='submit' name='purchase' value='Purchase'>
<input type='reset' value='Cancel'>
</td>
</tr>
</form>
<tr>
<td width='640' colspan='2'>
<center>
<a href='Index.Jsp'>[Back To Home]</a>
</center>
</td>
</tr>
<tr>
<td width='640' colspan='2'>
<%@ include file='Copyright.html' %>
</table>
</body>
</html>
And the code for the order processor
Code:
<%@page contentType="text/html" import="java.lang.Float" %>
<html>
<head><title>JSP Page</title></head>
<body>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
<%-- Get the variables from the referer page --%>
<%
//Declare the varaibles to hold the values
//String[] title, price, quantity;
String[] title;
String[] price;
String[] quantity;
//String total;
//For processing the price, quantity and total
Float flPrice, flQuantity;
//Fill in the variables
title= request.getParameterValues("title");
price = request.getParameterValues("cost");
quantity = request.getParameterValues("quantity");
//Some code to figure out the bill
flPrice = new Float(price[0]);
flQuantity = new Float(quantity[0]);
float totalCost = (flPrice.floatValue() * flQuantity.floatValue());
%>
<h1>THANK YOU</h1>
Your order is:
<br>
<b>Title:</b> <% out.print(title[0]); %><br>
<b>Quantity:</b> <%out.print(quantity[0]); %><br>
<b>Total:</b> <% out.print(totalCost); %><br>
</body>
</html>
I'm running Forte for Java and using the Tomcat server that came with Forte.