Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
A.11 The JSP page Directive: Structuring Generated Servlets
535
Example of Using setContentType 
ApplesAndOranges.jsp

Comparing Apples and Oranges

<% 
String format = request.getParameter("format");
if ((format != null) && (format.equals("excel"))) { 
  response.setContentType("application/vnd.ms excel");
}  
%>
  
ApplesOranges
  
First Quarter23074706
  
Second Quarter29825104
  
Third Quarter30115220
  
Fourth Quarter30555287
The isThreadSafe Attribute
<%@ page isThreadSafe="true" %> <%!   Default   %>
<%@ page isThreadSafe="false" %>
  A value of 
true
 means that you have made your code threadsafe and 
that the system can send multiple concurrent requests. A value of 
false
 means that the servlet resulting from JSP document will 
implement 
SingleThreadModel
 (see Section 2.6).
  Non threadsafe code:
<%! private int idNum = 0; %>
<% String userID = "userID" + idNum;
out.println("Your ID is " + userID + ".");
idNum = idNum + 1; %>
  Threadsafe code:
<%! private int idNum = 0; %>
<% synchronized(this) {
String userID = "userID" + idNum;
out.println("Your ID is " + userID + ".");
idNum = idNum + 1; 
} %>
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