I have a form that accepts a list of values, each value being listed on a separate line of textArea. In my Servlet, I am tokenizing the string I recieve from that textArea based on the new line characters "\r\n", like so:
String[] partNumberList = originalPartNumberString.split("\r\n");
This appears to work fine. I get an array of values as expected. I believe this is because the browser handles standardizing the way newlines are sent to the server, regardless of what OS / browser the form data is being sent from (see this post). I've tested in IE, Firefox, Chrome ... everything appears to work fine with that and I feel pretty confident about it.
After receiving the values on the server side, I then use those values for some looks ups, etc., then I write them back to the textArea for the response. In order to do so, I am writing it back in the same fashion I am receiving it ... I just build a new String, and separate each value with a "\r\n". I then set the value of the textArea to that String.
StringBuffer invalidReturnPartList = new StringBuffer("");
for (int i = 0; i < requestedPartList.length; i++)
{
invalidReturnPartList.append(requestedPartList[i]);
invalidReturnPartList.append("\r\n");
}
return invalidReturnPartList.toString();
This also tests OK for me in all browsers I have tried. However, I'm just nervous about whether I'm covering all my bases here ... if someone is running a Mac, will the "\r\n" translate correctly on their browser? What about Linux? I would think everything would be handled in the browser, but I am just not sure here... so my question is, does this look right to you, or have I missed something?
Thanks in advance.