Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use JSTL to add a table to the Future Value application In this exercise, you’ll

ID: 3598345 • Letter: U

Question

Use JSTL to add a table to the Future Value application

In this exercise, you’ll use JSTL to add a table to the Future Value application showing the value of a series of monthly investments at the end of each year.

Review the project

1. Download, unzip and open the project named ch09_ex3_futureValue.

https://drive.google.com/file/d/0B5HjVVkWJYBId184VW1zTmtJYnc/view?usp=sharing

2. Open the FutureValueServlet class. Note that the code in the doPost method has been modified to create a list of calculation objects, one for each year starting at one and going up to the number of years entered by the user. Also, note that it stores an attribute named calculations in the request.

Modify the code

3. Open the index.jsp file. Then, modify it so it uses the JSTL choose tags instead of JSTL

if tags.

4. Open the result.jsp file. Then, modify it so it presents a table that displays the value of the investment for each year up to the year the user entered. To do this, you can use a JSTL forEach tag. When you’re done, the user interface should look something like this:

5. Note that the Investment Amount, Yearly Interest Rate, and Number of Years fields are no longer working correctly. This is because the application stores multiple calculations instead of a single calculation.

6. Fix the application so the second page displays the Investment Amount, Yearly Interest Rate, and Number of Years fields again. There are several ways to do this. Choose the way that you think works best.

Download Files: https://drive.google.com/file/d/0B5HjVVkWJYBId184VW1zTmtJYnc/view?usp=sharing

Future Value Calculator Investment Amount Yearly Interest Rate: Number of Years: Year Value $1,219.68 $2,476.46 $3,771.46 $5,105.85 $6,480.83 4 Return to Calculator © 2014, Mike Murach and Associates

Explanation / Answer

<%@ page isErrorPage="false" errorPage="error.jsp" import="java.util.Set,java.util.Iterator,java.util.Map,java.util.Date,java.text.DateFormat,chat.*"%>

<%

String roonName = null;

String nickname = (String)session.getAttribute("nickname");

ChatRoomList roomList = null;

ChatRoom chatRoom = null;

Chatter chatter = null;

Message[] messages = null;

if (nickname != null)

{

try

{

roomList = (ChatRoomList) application.getAttribute("chatroomlist");

roonName = roomList.getRoomOfChatter(nickname).getName();

if (roonName != null && roonName != "")

{

chatRoom = roomList.getRoom(roonName);

chatter = chatRoom.getChatter(nickname);

if (chatRoom != null)

{

long enteredAt = chatter.getEnteredInRoomAt();

if (enteredAt != -1)

{

messages = chatRoom.getMessages(enteredAt);

}

else

{

messages = chatRoom.getMessages(chatter.getLoginTime());

}

}

else

{

out.write("<b>Room " + roonName + " not found</b>");

out.close();

}

}

}

catch(Exception e)

{

System.out.println("Exception: "+ e.getMessage());

throw new ServletException("Unable to get handle to ServletContext");

}

%>

<html>

<head>

<script language="javascript" src="assets/js/jquery-1.2.6.min.js"></script>

<!-- <script type="text/javascript">

function AutoRefresh(){

var xmlHttp;

try{

xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari

}

catch (e){

try{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer

}

catch (e){

try{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

catch (e){

alert("No AJAX");

return false;

}

}

}

xmlHttp.onreadystatechange=function(){

if(xmlHttp.readyState==4){

document.getElementById("AutoUpdte").innerHTML=xmlHttp.responseText;

// var ar=document.getElementById('AutoUpdte');

  

setTimeout('AutoRefresh()',1000);

// JavaScript function calls AutoRefresh() every 1 seconds

}

};

xmlHttp.open("GET","MessageContent.jsp",true);

xmlHttp.send();

}

AutoRefresh();

</script>-->

  

  

<script type="text/javascript">

function AutoRefresh(){

var auto = setInterval( function ()

{

$('#AutoUpdte').load('MessageContent.jsp').fadeIn("slow");

}, 1000); // refresh every 5000 milliseconds

}

AutoRefresh();

</script>

<!--<meta http-equiv="refresh" content="10">-->

<link href="css/bootstrap.css" rel="stylesheet" type="text/css">

<meta name="Author" content="Ideapot Business Consultancy">

<link href="css/chat.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="assets/js/jquery-1.4.1.js"></script>

<script type="text/javascript" src="assets/js/chat.js"></script>

  

<script language="JavaScript" type="text/javascript">

function reload()

{

window.location.reload();

}

function winopen(path)

{

chatterinfo = window.open(path,"chatterwin","scrollbars=no,resizable=yes, width=400, height=300, location=no, toolbar=no, status=no");

chatterinfo.focus();

}

</script>

</head>

<body bgcolor="#98AFC7">

<table width="100%" border="0" >

<tr>

<td width="80%" valign="top">

<%@ include file="header.jsp" %>

<table>

<tr>

<td id="AutoUpdte">

<h3><i>Welcome <%=(String)session.getAttribute("nickname")%></i> <br></h3>

<%

if(messages != null && messages.length > 0)

{

for (int i = 0; i < messages.length; i++)

{

Message message = (Message)messages[i];

String chatterName = message.getChatterName();

String strmsg = message.getMessage();

long time = message.getTimeStamp();

Date date = new Date(time);

if (chatterName.equalsIgnoreCase((String)session.getAttribute("nickname")))

{

out.write("<font face="Arial" size="2" color="blue"><b>" + chatterName + strmsg+"<br> ");

}

else if (chatterName.equalsIgnoreCase("system"))

{

out.write("<span class="error">" + strmsg+"</span><br> ");

}

else

{

out.write("<font face="Arial" size="2"><b>"+chatterName + "</b></font> " + strmsg + "<br> ");

}

}

out.write("<a name="current"></a>");

}

else

{

out.write("<font color="red" face="Arial" size="2">There are currently no messages in this room</font>");

}

out.write("<a name="current"></a>");

%>

</td>

</tr>

</table>

</td>

<td width="20%" valign="top" >

<table width="100%" cellpadding="2" cellspacing="0">

<tr>

<td>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#2C259C">

<tr>

<td>

<span class="white"><%=chatRoom.getNoOfChatters()-1%> people in ichat</span><br>

</td>

</tr>

</table>

<jsp:include page="index.jsp"></jsp:include>

<%

Chatter[] chatters = chatRoom.getChattersArray();

for(int i = 0; i < chatters.length; i++)

{

if (chatters[i].getName().equals(session.getAttribute("nickname")))

{

%>

<pre class="prettyprint"><font face="Arial" size="2" color="blue"><%=chatters[i].getName() + " (" +chatters[i].getSex() +")<br>"%></font></pre>

<%

}

else

{

%>

<!-- <pre class="prettyprint"> <font face="Arial" size="2"><a href="#""%>')"><%=chatters[i].getName()+" <br>"%></a> </font></pre>-->

<pre class="prettyprint"> <font face="Arial" size="2"><a href="#""%>')"><%=chatters[i].getName()+" <br>"%></a> </font></div></pre>

<%

//out.write("<font face="Arial" size="2"><a href="#"+chatters[i].getName() + "')" title="View information about "+chatters[i].getName()+"">"+ chatters[i].getName()+"</a> (" + chatters[i].getSex()+")</font><br>");

}

}

}

else

{

response.sendRedirect("login.jsp");

}

%>

</td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote