How to avoid duplication
Abstract: How to avoid duplication
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> More Java Pitfalls This is the Chinese version of an example.
First, what is to repeat
Imagine a visit of a very big booking sites when booking tickets click on the submit button, the server may be slow processing speed, tickets still can not see the result that the failure of the request to buy their own, so once again and over click Submit button, and if not addressed, these requests will be dealt with the server, which lead to false results.
Second, to prevent repeat
Web.xml looked at (the examples of directories and files download)
<? Xml version = "1.0">
Web-app PUBLIC "- / / Sun Microsystems, Inc / / DTD Web Application 2.3 / / EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<table Width="732" border="0"> <tr> <td width="442"> Id Id
</ Td> <td width="280"> </ td> </ tr> </ table>
Look at the form ticketForm.jsp
<% @ Page contentType = "text / html; GBK charset ="%>
<%
/ / The first time, the target set in a session id attribute to the success will be deleted. After the submission of this test will be whether the attribute value is null judge to repeat.
If (session.isNew ()) (
Session.setAttribute ( "id", session.getId ());
)
%>
Ozzie concerts online booking
<form Method="get" action="/resubmit/ControllerServlet">
<table Border="1" width="50%">
<tr>
<td> The number of votes: </ td>
<td>
<select Name="numTickets">
<option Value="Please enter a Ticket #"> Please enter a Ticket # </ option>
<Option value = "1 Ticket" <% if (resubmit.getNumTickets () == "a Ticket") out.println ( "SELECTED");%>> 1 Ticket </ option>
<Option value = "2 Tickets" <% if (resubmit.getNumTickets () == "Tickets") out.println ( "SELECTED");%>> 2 Tickets </ option>
<Option value = "Tickets" <% if (resubmit.getNumTickets () == "Tickets") out.println ( "SELECTED");%>> 3 Tickets </ option>
<Option value = "Tickets" <% if (resubmit.getNumTickets () == "Tickets") out.println ( "SELECTED");%>> 4 Tickets </ option>
<Option value = "5 Tickets" <% if (resubmit.getNumTickets () == "5 Tickets") out.println ( "SELECTED");%>> 5 Tickets </ option>
<Option value = "6 Tickets" <% if (resubmit.getNumTickets () == "6 Tickets") out.println ( "SELECTED");%>> 6 Tickets </ option>
<Option value = "7 Tickets" <% if (resubmit.getNumTickets () == "7 Tickets") out.println ( "SELECTED");%>> 7 Tickets </ option>
<Option value = "8 Tickets" <% if (resubmit.getNumTickets () == "8 Tickets") out.println ( "SELECTED");%>> 8 Tickets </ option>
<Option value = "9 Tickets" <% if (resubmit.getNumTickets () == "Tickets 9") out.println ( "SELECTED");%>> 9 Tickets </ option>
</ Select>
</ Td>
</ Tr>
<tr>
<td> Stadium Level: </ td>
<td>
<select Name="stadiumTier">
<option Value="Please enter a Stadium Tier"> Please enter a Stadium Tier </ option>
<Option value = "Tier A" <% if (resubmit.getStadiumTier () == "Tier A") out.println ( "SELECTED");%>> Tier A </ option>
<Option value = "Tier B" <% if (resubmit.getStadiumTier () == "Tier B") out.println ( "SELECTED");%>> Tier B </ option>
<Option value = "Tier C" <% if (resubmit.getStadiumTier () == "Tier C") out.println ( "SELECTED");%>> Tier C </ option>
<Option value = "Tier D" <% if (resubmit.getStadiumTier () == "Tier D") out.println ( "SELECTED");%>> Tier D </ option>
<Option value = "Tier E" <% if (resubmit.getStadiumTier () == "Tier E") out.println ( "SELECTED");%>> Tier E </ option>
</ Select>
</ Td>
</ Tr>
<tr>
<td> Votes Price: </ td>
<td>
<select Name="ticketPrice">
<option Value="Please enter a Ticket Price"> Please enter a Ticket Price </ option>
<Option value = "$ 12" <% if (resubmit.getTicketPrice () == "$ 12") out.println ( "SELECTED");%>> $ 12 </ option>
<Option value = "$ 17" <% if (resubmit.getTicketPrice () == "$ 17") out.println ( "SELECTED");%>> $ 17 </ option>
<Option value = "$ 25" <% if (resubmit.getTicketPrice () == "$ 25") out.println ( "SELECTED");%>> $ 25 </ option>
<Option value = "$ 35" <% if (resubmit.getTicketPrice () == "$ 35") out.println ( "SELECTED");%>> $ 35 </ option>
<Option value = "$ 50" <% if (resubmit.getTicketPrice () == "$ 50") out.println ( "SELECTED");%>> $ 50 </ option>
</ Select>
</ Td>
</ Tr>
<tr>
<td Colspan="2" align="center"> <input TYPE="submit" VALUE="Submit"> </ td>
</ Tr>
</ Table>
</ Form>
</ Body>