• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to handle single quote?

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the code..
iam having the data with single quote as value for the list box..
while retrieving the data is truncated at the single quote position, can any suggest me the ways of solving this problem..

here is the code..while retrieving list box value, iam getting only Father instead of Father's Name


<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<%
if (request.getParameter("submit")!=null)
{
out.println(request.getParameter("s"));
}
%>
</HEAD>
<%String str="Father's Name";
%>
<BODY>
<form >
<SELECT NAME="s">
<option value='<%=str%>'><%=str%></option>
</SELECT>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</BODY>
</HTML>
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhishek Reddy Chepyala:
here is the code..
iam having the data with single quote as value for the list box..
while retrieving the data is truncated at the single quote position, can any suggest me the ways of solving this problem..

here is the code..while retrieving list box value, iam getting only Father instead of Father's Name


<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<%
if (request.getParameter("submit")!=null)
{
out.println(request.getParameter("s"));
}
%>
</HEAD>
<%String str="Father's Name";
%>
<BODY>
<form >
<SELECT NAME="s">
<option value='<%=str%>'><%=str%></option>
</SELECT>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</BODY>
</HTML>


You can use this:

it will work..
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Qussay Najjar:


You can use this:

it will work..


sorry, for my typing mistake.. it should be..
[CODE]
str = str.replace("\'","\'\'");
[CODE]
instead of
[CODE]
str = str.replace('\'','\'\'');
[CODE]
notice the double quotes("") in the replace parameters.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnak you Qussay Najjar for the reply

i have tried your code, but it is not working.
have you tried ?
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhishek Reddy Chepyala:
thnak you Qussay Najjar for the reply

i have tried your code, but it is not working.
have you tried ?


Yes, I tried the second one, and it's working with oracle DB.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply again..
i have tried, but it is not working, i don't know where i went wrong.
can you look at the following code and tell me where i went wrong?
here is the code ..

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<%
if (request.getParameter("submit")!=null)
{
out.println("<div align=right><a href='test.jsp'>back</a></div>");
out.println(request.getParameter("s"));
}
%>
</HEAD>
<%String str="Father's Name";
str=str.replace("\'","\'\'");
%>
<BODY>

<form >
<SELECT NAME="s">
<option value='<%=str%>'><%=str%></option>
</SELECT>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</BODY>
</HTML>
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay my friend,,
If your page is just like that, you don't have to do that
"replace" technique (this one you use only when you're saving to DB, because
Database quires won't work with single quotes.
but in your case, you went wrong in this line.




just change the single quotes for the value to double ones, like this:



and later on if you needed to save this name to DB, you change it in the servlet that is receiving the request from this jsp page..
Got it...?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic