|
-
September 29th, 1999, 11:03 PM
#1
Servlet Syntax
Greetings Gurus! I need help understanding this syntax:
ServletInputStream sis = req.getInputStream();
byte[]buf = new byte[4096];
sis.read(buf);
String name = new String(buf).trim().toUpperCase();
PrintWriter pw = res.getWriter();
It's really the 4th line that confuses me. I didnt know that syntax is legal. Could someone explain to me in detail 'String(buf).trim().toUpperCase()? In fact explaining the whole thing wouldnt hurt . NOTE: I do know that the PrinterWriter object can be replaced by the ServletOutputStream object. I didnt know u can have a type byte[] variable. I need a clearer understanding of what this does.
Thanks!
Dino
-
September 30th, 1999, 12:58 PM
#2
Re: Servlet Syntax
String name = new String(buf).trim().toUpperCase();
// is equal to
Sting name = new String(buf); // Creates a String oject of buf.
name = name.trim(); // removes the white spaces.
name = name.toUpperCase(); // converts the value to upper case...
Meher
-
September 30th, 1999, 06:00 PM
#3
Re: Servlet Syntax
Thanks Meher.
I just found the interpretation of that line while reading your response. Yes it just calls the constructor with a 'buf' parameter then it removes white spaces by .trim() then converts the value to Uppercase using .toUpperCase().
from a left to right order. I just didnt know that syntax was legal. Perhaps the authors of my book were simply too lazy to write the methods individually but thanks for the reply anyway. 
Dino
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|