JSP 和添加 JSP 表达式 Scriptlet 返回的字符串
当尝试执行以下操作时,我在 IE 中遇到“预期错误 ')'” 的脚本错误:
alert(<%=SystemConfig.getTranslatedTextByKey(LBIBOConstants.LANG_KEY_MODIFYTIME_ALRTMISSINGA, userLocale)%> + strMessageString + <%=SystemConfig.getTranslatedTextByKey(LBIBOConstants.LANG_KEY_MODIFYTIME_ALRTMISSINGB, userLocale)%>);
我最初只想提前添加一个字符串来发出警报,但我也尝试过,但也没有成功。
我的猜测是你不能做这样的事情,但我没有很多其他选择(代码是由其他人开发的,所以我知道有比 Scriptlet 更好的选择)。
无论如何,JSP 表达式返回的这些字符串可以在constants.java 文件中找到,该文件又从语言包中加载,以防大家都想知道。我已经仔细检查过这些,它们都很好。
当一个值是页面内的 var 并且其他值位于 scriptlet 标记内时,如何将这些字符串添加在一起?是否可以?
I am having script errors of "Error expected ')'" in IE when attempting to do the following:
alert(<%=SystemConfig.getTranslatedTextByKey(LBIBOConstants.LANG_KEY_MODIFYTIME_ALRTMISSINGA, userLocale)%> + strMessageString + <%=SystemConfig.getTranslatedTextByKey(LBIBOConstants.LANG_KEY_MODIFYTIME_ALRTMISSINGB, userLocale)%>);
I would originally like to just alert with one string added together ahead of time, but I'ved tried that with no luck either.
My guess is you can't do something like this, but I don't have many other options (the code was developed by someone else, so I understand there are better alternatives than Scriptlets).
Regardless, these strings returned by JSP expressions are found in a constants.java file, which are in turn loaded from a language package, in case you all were wondering. I have double checked these, and they are just fine.
How can I add these strings together when one value is a var within the page, and the other values are within scriptlet tags? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSP = 服务器端
JavaScript = 客户端
JSP 生成的 JavaScript 代码必须是有效的 JavaScript 代码。使用浏览器的“查看页面源代码”菜单项查看生成的 JavaScript,并修复 JSP 代码,以便生成有效的 JavaScript 代码。
如果您的 JSP 生成了不正确的 HTML 代码,您将如何处理。
您可能遗漏了一些引言。但还要确保 scriptlet 表达式不会返回应该由 JavaScript 转义的字符。或者使用 commons-lang StringEscapeUtils.escapeEcmaScript 转义这些字符:
并且表达式 (...) 应该是转义的表达式:
JSP = server-side
JavaScript = client-side
The JavaScript code that the JSP generates must be valid JavaScript code. Look at the generated JavaScript using your browser "View page source" menu item, and fix the JSP code so that it generates valid JavaScript code.
Exactly how you would do if your JSP generated incorrect HTML code.
You're probably missing some quotes. But also make sure that the scriptlet expression don't return characters that should be JavaScript-escaped. Or use commons-lang StringEscapeUtils.escapeEcmaScript to escape those characters :
And the expressions (...) should be your expressions escaped: