• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want urgent Help  RSS feed

 
khad M
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers
want help.
Iam inserting 2 consecutive backslashes "(\)"into textfield of a JSP page.
In view that field is showing only single backslash instead of two.
How to avoid this problem .
Let me know ASAP.
thanks in Advance
Regards
Khad M
SCJP2.0
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use 4 backslashes...a backslash is an escape character, so when you do \\ you'll get one. The reason is because the compiler sees the first backslash as escape character, then it reads the second one as the character to interpret. So it would see \\\\ like <escape>\<escape>\ and read it as \\. Below is an example in a JSP:
<%
out.println("This will print one backslash \\");
out.println("This will print two backslashes \\\\");
%>
Hope this helps...
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh! I think I must have replied before a good dose of caffine! The front slash is an escape character -- no the backslash...
I'll go back to sleep now!
 
gautam shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Leilani Ames:
Duh! I think I must have replied before a good dose of caffine! The front slash is an escape character -- no the backslash...
I'll go back to sleep now!

backslash belongs to escape sequence not forward slash i think.....
Microsoft and caffine .hummmm . combination is very dangerous.
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh geez! An example of what happens when you combine Java, caffiene, with a shot of MS! My brain must have been short circuited
 
khad M
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ames
thanks for the reply.
But still the problem is..........
when an user enters some backslash characters
(which i don't know how many)then in view should also so many backslashes should appear.....Right!!! .
So what's the solution for this?
Khad M
SCJP2.0
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i think you can replace the slashes with some special character whenever user submits data and on the contrary just replace the special character with the "/" whenever you are displaying..
Pranit..
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We had a similiar type of dilemma on a project. The users were free to enter text and to use any characters they wanted. What we did was create a javascript function that parsed the information before it went to the view.
If the user input:
D:\mydir\yourdir
You would parse it to be handled as:
D:\\mydir\\yourdir
Then it would display on the following JSP page as:
D:\mydir\yourdir
Does this help any?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!