Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
250
Chapter 11 The JSP page Directive: Structuring Generated Servlets
Listing 11.1 ImportAttribute.jsp 
The import Attribute
      HREF="JSP Styles.css"
      TYPE="text/css">

The import Attribute

<%   JSP page directive   %>
<%@ page import="java.util.*,coreservlets.*" %>
<%   JSP Declaration (see Section 10.4)   %>
<%!
private String randomID() {
  int num = (int)(Math.random()*10000000.0);
  return("id" + num);
}
private final String NO_VALUE = "No Value";
%>
<%   JSP Scriptlet (see Section 10.3)   %>
<%
Cookie[] cookies = request.getCookies();
String oldID = 
  ServletUtilities.getCookieValue(cookies, "userID", NO_VALUE);
String newID;
if (oldID.equals(NO_VALUE)) {
  newID = randomID();
} else {
  newID = oldID;
}
LongLivedCookie cookie = new LongLivedCookie("userID", newID);
response.addCookie(cookie);
%>
<%   JSP Expressions (see Section 10.2)   %>
This page was accessed at <%= new Date() %> with a userID
cookie of <%= oldID %>.
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