如何将带空格和括号的文本传递给java
我将一个值作为请求属性传递给jsp页面如何将带空格和括号的文本传递给java,java,javascript,jsp,jstl,apache-stringutils,Java,Javascript,Jsp,Jstl,Apache Stringutils,我将一个值作为请求属性传递给jsp页面 request.setAttribute("description", StringEscapeUtils.escapeHtml("Hello 1F World (Hello World) Hello World")); 在jsp页面中,我在pageContext中进行设置 String text = (String) (String) request.getAttribute("description"); pageContext.setAttribu
request.setAttribute("description", StringEscapeUtils.escapeHtml("Hello 1F World (Hello World) Hello World"));
在jsp页面中,我在pageContext中进行设置
String text = (String) (String) request.getAttribute("description");
pageContext.setAttribute("description", text);
我必须将此文本作为请求参数发送到服务器。当我查看firebug时,我看到一个错误。我试图使用“value”=“${text}”
,这会引发错误。我做错了什么
SyntaxError: unterminated string literal
[Break On This Error]
{ "name": "description", "value": "
您应该使用
StringEscapeUtils.escapeJava
查看没有任何HTML的字符串内容
StringEscapeUtils.escapeJava("Hello 1F World (Hello World) Hello World"));
您忘记显示将文本发送到服务器所涉及的代码。你到底是怎么做到的?编辑我猜你正在把这个字符串放到页面上的一些JavaScript代码中。您需要使用类似于JSON编码器的工具来确保获得有效的JavaScript字符串常量。是的,我正在将该文本放回JavaScript代码中,问题是,您需要确保字符串的格式正确,以便JavaScript解析器将其作为有效的字符串常量接受。最简单的方法是使用JSON编码器。不幸的是,标准JSTL函数库中没有这样的东西。