0

I am relatively new to working with JSPs and I have a feeling I'm overlooking something simple. I have a segment that appends a key onto a URL before sending the user back to where they came from. The key is a string value and when it consists of only numberic values(for example 12345) it works fine, but when it contains non-numerics(for example abcde) it simply appends "#" to the url and stays on the same page.

<core:when test="${dataTransferObject.someBoolean}">
<a href="#" onclick="javascript:location='path/back/to/their/home.request?cachekey='+<core:out value="${dataTransferObject.stringVariable}"/>;return false;">Back to Home </a>
</core:when>
4

1 回答 1

0

当它是一个字符串时,JavaScript 将是非法的——它会认为您正在尝试引用一个不存在的 JavaScript 变量。您将在 JavaScript 控制台中看到一个错误。

不要做任何 JavaScript 操作;JSP 在客户端看到之前在服务器端进行评估:

onclick="javascript:location='path/back/to/their/home.request?cachekey=<core:out value="${dataTransferObject.stringVariable}"/>';return false;"

更好的是,使用 JSP EL:

onclick="javascript:location='path/back/to/their/home.request?cachekey=${dataTransferObject.stringVariable}';return false;"

此外,如果这是 JSTL 核心标记库,则规范前缀为"c".

于 2012-07-03T15:14:13.407 回答