I have an iframe which includes src like this:
<iframe id="frame1" src="/jsp/transfer/a.jsp?isChange=true&bizId="+bizId></iframe>
bizId is a number. For example:
src = "/jsp/transfer/a.jsp?isChange=true&bizId=10"
I notice that Javascript will make put bizId's value in quotes: "10", "null", etc. I want to get the actual numeric value, not a string. Why is it represented as a string? What should I do?
If I understood your problem right (especially your last comment), you need to do this:
<iframe id="frame1" src="/jsp/transfer/a.jsp?isChange=true&bizId=<%=bizId>"></iframe>
Explanation:
<%= variable >
- is a JSP syntax for inserting variables from JSP context into rendered HTML. This code (<%= variable >
) will be replaced fully by contents of variable
.
Added: (in response to comment)
If you need to put some variable into JavaScript file which is included from your original JSP file, you wont be able to use <%= variable >
syntax in it. However, here is what you can do:
[yourjsp.jsp]
<script>
var bizId = <%=bizId>;
</script>
...
<script src="yourjavascript.js"></script>
[yourjavascript.js]
function someMethod() {
alert(bizId);
}
Basically, JSP code will be replaced, and you will define a global javascript variable called bizId
containing the value of server-side bizId
. Then, any other javascript code can use that variable.