如何在查询字符串中使用回车或换行?
客户可以在文本区域中输入行,并将其保存在数据库中。
如果客户返回站点,他可以加载之前输入的数据。
但是,换行符和回车符不会显示在文本区域中。
我可以将它们放在查询字符串中,例如通过 ASCII 编码:%A 或 %D,但 java 不喜欢这样并抛出 IllegalArgumentException。
所以我现在做: %5Cn 和 %5Cr 给出: \n 和 \r
如何使 javascript 将转义的新行显示为文本区域中的实际新行?
URL 类似于:
http://www.abc.com?textarea=line1%5Cn %5Crline2
我希望 line1 和 line2 位于文本区域中的两个不同行上。
the customers can enter lines in a text area and this is saved in the database.
If the customer comes back to the site he can load the previously entered data.
However, the line feeds and carriage returns aren't displayed in the text area.
I can place them in the query string for example by ASCII coding them: %A or %D but java doesn't like that and throws an IllegalArgumentException.
So I do now: %5Cn and %5Cr which gives: \n and \r
How can I make javascript to display the escaped new lines as actual new lines in the text area?
The URL is something like:
http://www.abc.com?textarea=line1%5Cn%5Crline2
and I want the line1 and line2 to be on two different lines in the textarea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
%5C
是一个反斜杠 - 因此%5Cn
表示“反斜杠然后是字母 n”。您可能想要的是%0A
和%0D
,而不是%A
和%D
。但是您应该正确地对整个字符串进行 URL 编码,而不是仅仅手动编码两个字符。使用encodeURIComponent()
。另外,使用POST
而不是GET
,但这不是因为字符串是多行的,而是因为您将其存储在数据库中。您不应将GET
方法用于非幂等的操作。%5C
is a literal backslash - so%5Cn
means just "backslash and then the letter n". What you probably want is%0A
and%0D
instead of%A
and%D
. But you should URL-encode the entire string properly and not just encode two characters by hand. UseencodeURIComponent()
. Also, usePOST
instead ofGET
, but not because the string is multiline but because you are storing it in the database. You shouldn't use theGET
method for operations that are not idempotent.