How can I further optimize my servlets?

Govind Seshadri

You can always wring out some efficiency by making use of a StringBuffer or ByteArray.

For example, instead of sending your HTML to the client using a PrintWriter or some other output stream, you can write it out to a StringBuffer, and send it to the client using just one write invocation. Of course, you'll have to indicate the length of your data stream in the HTTP header too as shown below:

 PrintWriter out = res.getWriter();
 StringBuffer sb = new StringBuffer();
 ...
 //concatenate html to StringBuffer
 //set len and write it out
 res.setContentLength(sb.length());
 out.print(sb);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact