HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"High-Performance Web Applications Using the Java
 Servlet API and JSPs"
Volume: 5 Issue: 1, p.72

	

Listing 1: HelloWorldServlet.java 

import java.io.*; 
import javax.servlet.*; 
import javax.servlet.http.*; 
  

public class HelloWorldServlet extends HttpServlet { 
  

public void doGet (HttpServletRequest req, HttpServletResponse res) 
    throws ServletException, IOException 
    { 
            res.setContentType("text/html"); 
               String name = req.getParameter 
("name"); 
               If (name == null) 
                 name = "world"; 
  

               PrintWriter out = res.getWriter(); 
               out.print("<html>"); 
               out.print("<head><title>Hello 
World</title></head>"); 
               out.print("<body>"); 
               out.print("<h1>Hello " + name + 
"</h1>"); 
               out.print("</body></html>"); 
    } 
} 

Listing 2: HelloWorld.jsp 

<html> 
<head><title>Hello World</title></head> 
<body> 
<% String name=request.get parameter ("name"); 
if (name == null) 
     name = "world"; 
%> 
<h1>Hello <%= name %> </h1> 
</body> 
</html> 

 
Listing 3: ServerSessionServlet.java and ClientParameterServlets.java 
  
public class ServerSessionServlet extends HttpServlet { 

public void doGet (HttpServletRequest req, HttpServletRe- sponse res) 
throws ServletException, IOException 
            { 
    HttpSession session = req.getSession (); 
    -- 
    UserInfo info = search4user (session.getValue 
    ("username")); 
    } 
} 
   public class ClientParametersServlet extends HttpServlet { 
  
   public void doGet (HttpServletRequest req, HttpServletResponse res) 
   throws ServletException, IOException 
   { 
   String username = req.getParameter ("username"); 
  
   UserInfo info = search4user (username); 
   } 
} 
  
  

Listing 4: Pooling of resources (UnpooledServlet.java and PooledServlet.java 
  

 public class UnpooledServlet extends HttpServlet { 
  
 public void doGet (HttpServletRequest req, HttpServletRe- sponse res) 
 throws ServletException, IOException 
 { 
  res.setContentType("text/html"); 
 .... 
 ExpensiveObject o = new ExpensiveObject ( .... ); 
 .... 
 } 
} 

 public class PooledServlet extends HttpServlet { 
  
  public void init (ServletConfig config) 
   { 
    super.init (config); 
 expensiveObjectPool = new ExpensiveObjectPool(); 
 for (int i = 0; i < l0; i++) 
 expensiveObjectPool.add (new ExpensiveObject ( ....)); 
 } 
  
 public void doGet (HttpServletRequest req, HttpServletResponse res) 
  
 throws ServletException, IOException 
  { res.setContentType("text/html"); 
 ... 
 ExpensiveObject o = expensiveObjectPool.get (); 
 ... 
 expensiveObjectPool.recycle (o); 
  
 } 
} 



 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.