Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

<%=initPage%> vs "<%=initPage%>"  RSS feed

 
Calson LI
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I would like to send String variable content from JSP to Javascript. So
I tried the following fragment in one JSP file. May I know why the <%=initPage%> worked in the 2nd line but not in the <script> tags. In <script> tags, <%=initPage%> must be enclosed either in single quote or double quotes. Could anyone explain the difference between <%=initPage%> and "<%=initPage%>"?

<% String initPage="abc"; %>
The string variable is <%=initPage%>

<script language="Javascript">
var initPageFromJSP="<%=initPage%>";
alert(initPageFromJSP);
</script>

Thanks a lot,
Calson
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Carlson LI",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference whatsoever. The quotes are merely part of the template text that will become part of the HTML page. They are meaningless to the JSP translator.
 
Calson LI
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for your reply and advice.

Firstly, I felt more confused after reading the display naming rule. 'Calson' is my first name, 'LI' is my last name. Could you point out exactly what display name shall I follow?

Secondly, could you use some examples to explain 'no difference' between <%=initPage%> and "<%=initPage%>".

Thank you,
Calson
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use PM (private message) to discuss the name issue.

The quotes in your example are just template text that are sent to the browser as part of the HTML page just like any other template text such as HTML or JavaScript code.

The two examples are the same because the quotes are meaningless to the JSP translator, all it pays attention to is the <%=initPage%> part of each example.
[ August 19, 2008: Message edited by: Bear Bibeault ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!