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\nin 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 - POSTdata. In that case, the HTML 4 spec says that line breaks are encoded as %-escaped- CR LFsequences.
- The HTML 4 spec does not deal with the case where the textarea data is sent as URL query parameters; e.g. in a - GETrequest.
- The HTML 5 spec says that the "value" of the textarea is converted to - CR LFsequences, 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.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论