Question

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?

Was it helpful?

Solution

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 :

alert('<%= ... %>' + strMessageString + '<%= ... %>');
      ^----------^----------------------^----------^-- quotes!

And the expressions (...) should be your expressions escaped:

StringEscapeUtils.escapeEcmaScript(yourOriginalExpression)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top