SOLUTIONS(RATED A+)
The client-side consists of... - ANSWER- Structure (HTML)
- Style (CSS)
- Behavior (javascript)
The client-side sends a request to the server side, and the web server does what? -
ANSWERHandles traffic and determines what to do with the request
The application server creates a response using what model? - ANSWERMVC = Model
(pojos) - View (jsp) - Controller (servlet)
How does the JSP pass information to the servlet (controller)? - ANSWERThe JSP
passes information to the java servlet using url mapping (hyperlink or form action)
- Example using a form:
<h1>Enter your information: </h1>
<form name="loanForm" action="amortize" method="post" >
<label>Loan Principal: </label>
<input type="text" name="principal" value="0" />
<br>
<label>Loan Term(years): </label>
<input type="text" name="term" value="0" />
<br>
<label>Loan Rate(as a percentage (7 = 7%)): </label>
<input type="text" name="rate" value="0" />
<br>
<input type="submit" name="amortButton" value="Go" />
</form>
What does the servlet do with the data received from the JSP? - ANSWERUses POJOS
as needed from the model to create a view to send back to the appropriate JSP
- Amortization example
// Create Loan object
Loan loan = new Loan(principal, rate, term);
// Create Amortization object
Amortization amort = new Amortization(loan);
, // do the Amortization
String result = amort.doAmortization();
// set the url mapping
String url = "/amortization.jsp";
// add values to request object to pass to the destination
request.setAttribute("result", result);
// send control to the appropriate JSP
RequestDispatcher dispatcher = request.getRequestDispatcher(url);
dispatcher.forward(request, response);
How do you pull information from the servlet to the JSP? - ANSWERCreate a java
scriplet in html and use the request attribute to pull the information from the servlet.
- Amortization example:
<%
double principal = Double.parseDouble(request.getParameter("principal"));
double rate = Double.parseDouble(request.getParameter("rate"));
int term = Integer.parseInt(request.getParameter("term"));
String result = (String) request.getAttribute("result");
%>
What is the difference between a java script and java expression? - ANSWER- A java
scriplet is used to handle information from the servlet and set fieldNames to
values/methods
- A java expression is used to display the values/methods using the given fieldName
- java scriplets are <% code; %>
- java expressions are <%= fieldName %>
What is a stateless protocol? - ANSWER- A communications protocol that treats each
request as an independent transaction
- A stateless protocol does not require the server to retain session information
What is a stateful protocol? - ANSWER- A protocol which requires the keeping of
internal state.
Requests and responses to our web applications are sent via the... - ANSWERHTTP
protocol
- HTTP is a stateless protocol