wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes problem in including jsp custom tags in javascript functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem in including jsp custom tags in javascript functions" Watch "problem in including jsp custom tags in javascript functions" New topic
Author

problem in including jsp custom tags in javascript functions

srinu reddy
Greenhorn

Joined: Oct 21, 2007
Posts: 12
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
srinu reddy
Greenhorn

Joined: Oct 21, 2007
Posts: 12
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: Oct 21, 2007
Posts: 12
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

Joined: Feb 08, 2006
Posts: 948
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in including jsp custom tags in javascript functions