Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in including jsp custom tags in javascript functions

 
srinu reddy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am having problem while passing jsp custom tags tp javascript.
The problem is Unterminated string literal.
please, help me out
the code is something like this

<script>
show('<adc:get name="SigningMode" />');
toggleSigningConfig('<adc:get name="SigningMechanism" />');
</script>
Thanks & Regards
srinu reddy
[ March 07, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If any of the values emitted by the custom tags contain un-escaped quote characters, of course you are going to run into trouble. Your tags will need to make sure that any value that they emit are properly escaped for use as JavaScript string literals.
 
srinu reddy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it returns string literal how to deal with.
the converted servlet code is something like this


out.write("<script>\r\n");
out.write("show('");
if (_jspx_meth_adc_get_1(_jspx_page_context))
return;
out.write("');\r\n");
out.write("toggleSigningConfig('");
if (_jspx_meth_adc_get_2(_jspx_page_context))
return;
out.write("');\r\n");
out.write("</script>\r\n");


the above piece of code is converted servlet giving problem ,
then how to deal that.

regards
srinu
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your tag is emitting script that you then put inside a JavaScript string literal? Surely you can come up with something less convoluted?

In any case, if what your tag is emitting text that is to be embedded inside a JavaScript string literal, it must ensure that all quote characters are escaped with \.
 
srinu reddy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my tag is emmiting text. i tried with \(escape sequence) but not working.
still it is saying unterminated string literal.

script is here....
<script>
show('<adc:get name="SigningMode" />');
toggleSigningConfig('<adc:get name="SigningMechanism" />');
</script>

generated servlet code for the above is here............

out.write("<script>\r\n");
out.write("show('");
if (_jspx_meth_adc_get_1(_jspx_page_context))
return;
out.write("');\r\n");
out.write("toggleSigningConfig('");
if (_jspx_meth_adc_get_2(_jspx_page_context))
return;
out.write("');\r\n");
out.write("</script>\r\n");

javascript error is here .....

Unterminated String literal
show('Attended....

I think it is not finding the ending quote properly.
As you doubted in the previous reply it is only emitting text (either Attende or Unattended). please, suggest me a solution for the above.


Regards,
srinu reddy etta.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is adc:get a custom tag that you wrote (or at least have the source code for)? It sure seems like the issue is with what the custom tag is returning. I cannot say I have looked much at generated servlet code for custom tags. What would cause either of those return statements to execute? That path sure seems like it would result in an unterminated string.

- Brent
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Showing us the unprocessed tags is not useful. Do a View Source in the browser and you will see what is being returned to the browser so that you can figure out what's not being formatted correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic