Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
15.3 Including Static or Dynamic Content
375
Listing 15.9 HotelInfo.java 
package coreservlets;
/** Simple class describing a hotel name and associated
 *  frequent guest number, used from the TravelData class
 *  (where an array of HotelInfo is associated with
 *  each customer).
 */
public class HotelInfo {
  private String hotelName, frequentGuestNumber;
  public HotelInfo(String hotelName,
                   String frequentGuestNumber) {
    this.hotelName = hotelName;
    this.frequentGuestNumber = frequentGuestNumber;
  }
  public String getHotelName() {
    return(hotelName);
  }
  public String getfrequentGuestNumber() {
    return(frequentGuestNumber);
  }
}
15.3 Including Static or Dynamic 
Content
If a servlet uses the 
forward
 method of 
RequestDispatcher
, it cannot actu 
ally send any output to the client it must leave that entirely to the destina 
tion page. If the servlet wants to generate some of the content itself but use a
JSP page or static HTML document for other parts of the result, the servlet
can use the 
include
 method of 
RequestDispatcher
 instead. The process is
very similar to that for forwarding requests: call the 
getRequestDispatcher
method of 
ServletContext
 with an address relative to the server root, then
call 
include
 with the 
HttpServletRequest
 and 
HttpServletResponse
.
The two differences when 
include
 is used are that you can send content to
the browser before making the call and that control is returned to the servlet
after the 
include
 call finishes. Although the included pages (servlets, JSP
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved