效率创建安全的Java应用, 第1部分(16)
时间:2012-01-14 IBM Tyler Anderson
表 9. 定义房产页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:useBean id="realestate" class="com.ibm.ds.realestate.RealestateDataImpl"
scope="page" />
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.util.Iterator" %>
<%@page import="com.ibm.ds.realestate.Realestate" %>
<%@page import="pureQuery.example.*" %>
<%@page import="com.ibm.pdq.runtime.*" %>
<%@page import="java.math.BigDecimal" %>
<html>
<head>
<title>realestate</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<!-- Here we login to the database again to fetch all real
estate holdings in the
realestate table, same database connection URL as before. -->
<h1>Your realestate holdings</h1>
<table border="1"><tr><th>Address</th>
<th>City</th><th>Zip</th>
<th>State</th><th>Value</th></tr>
<%
String userid = (String)session.getAttribute("userid");
if(userid == null){
response.sendRedirect("login.jsp");
}
Data d = SampleUtil.getData("jdbc:db2://localhost:50000/WEALTH",
"<enter_your_username>", "<enter_your_password>");
realestate.setData(d);
Iterator i = realestate.getRealestates(userid);
Realestate curr = null;
double total = 0;
while(i.hasNext()){
curr = (Realestate) i.next();
out.println("<tr><td>"+curr.getAddress()+"</td>
<td>"+curr.getCity()+
"</td><td>"+curr.getZip()+"</td>
<td>"+curr.getState()+
"</td><td>contentquot;+curr.getPropertyValue()+"</td>
</tr>");
total += curr.getPropertyValue().doubleValue();
}
if(total > 0)
total = Math.round(total*100.0)/100.0;
%>
</table>
<h3>Total value: contentlt;% out.print(total); %></h3>
<h4>Enter new real estate:</h4>
<%
String address = request.getParameter("address");
String city = request.getParameter("city");
String zip = request.getParameter("zip&
|