13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

19.5 Review439into JSP files. The main servlet class (BudgetProServlet.java) is thus “gutted”of its output, and the new versi<strong>on</strong> (BudgetProC<strong>on</strong>troller.java) actsas the c<strong>on</strong>troller. Requests come to it via HTTP requests, but for output, itredirects the browser making that request over to the appropriate JSP.This introduces a new bit of servlet syntax—redirecting a request toanother URL. The acti<strong>on</strong> is taken by means of a method call <strong>on</strong> the HTTPresp<strong>on</strong>se object:resp<strong>on</strong>se.sendRedirect("BPAcct");Whereas in the previous, servlet versi<strong>on</strong> of BudgetPro, we would create anobject that was the next page of output:nextPage = new AccountView(current);In this versi<strong>on</strong>, we instead redirect the resp<strong>on</strong>se to a JSP that produces theoutput for that page.So how does the JSP know for which account it should display informati<strong>on</strong>?That is shared between the JSP and the c<strong>on</strong>troller servlet via the sessi<strong>on</strong>informati<strong>on</strong>. As with the previous, servlet-base BudgetPro, the sessi<strong>on</strong> is usedto store the current account. It can be retrieved from the sessi<strong>on</strong> informati<strong>on</strong>,as seen in line 11 of BPAcct.jsp:11:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!