• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain this syntax?

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) Please explain me this syntax? Why there so many "\"? who to remmber it?

out.println("<a href=\""+response.encodeURL("index.jsp")+ "\">test</a>") ;


 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just plain old Java. When you want to use a double quotation in a string, you've got to escape it. You should have learned that in SCJP.
 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Its like out.println("Str1"+response.encodeURL("index.jsp")+"Str2");

here Str1 is <a href=\"
and Str2 is \">test</a>

In these you are escaping the double quote(") cause you want the double quote to appear in the output.

you want to have following HTML tag in the response:
<a href="encodedURL">test</a>
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bindu Lakhanpal wrote:
here Str1 is <a href=\"
and Str2 is \">test</a>

Small typo I guess, they should read :

here Str1 is <a href="
and Str2 is ">test</a>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic