开发者

JSF textarea and newline, what is stored on server side?

There is a <textarea> element on a JSF page, user inputs several lines and开发者_高级运维 submits the form. What line delimiter do I expect on the server side?

  • \r\n in case user's OS is Windows, \n - when Unix
  • line delimiter depends on OS where my JSF servlet is running
  • line delimiter is always \n (Java internal one)


The HTML 4.0.1 spec mandates CR LF (\r\n) for line breaks in both application/x-www-form-urlencoded and multipart/form-data requests.

Neither the Servlet spec nor the JSF spec seem to have anything to say about line delimiters.


I think the complete answer is a bit more complicated:

  • @McDowell's answer deals with the case where the textarea data is sent as POST data. In that case, the HTML 4 spec says that line breaks are encoded as %-escaped CR LF sequences.

  • The HTML 4 spec does not deal with the case where the textarea data is sent as URL query parameters; e.g. in a GET request.

  • The HTML 5 spec says that the "value" of the textarea is converted to CR LF sequences, which covers all cases ... including (I presume) the case where the control's value is accessed from a client-size script. The value will then be %-escaped when encoded for transmission.

In summary, the specs say CR LF (i.e. \r\n) where they say anything, but it is possible that you could see CR or LF with some HTML 4 or older browsers on some platforms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜