Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Please explain this syntax?

 
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>") ;


 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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.
 
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>
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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>
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic