This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help outputting double quotes  RSS feed

 
kishore mukkamala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me on this.
I am building a search page (jsp) using weblogic and contains a simple text field which takes the user's query string and outputs the results. Once the page is loaded with the hits, I am displaying the user's query string in the text field. How ever, when a user enters the query string in quotes (ex: "test"), I have a problem displaying the string. Obviously, the value for the text filed is interpreted as ""test"" by html and is ignored completely.
I have tried using the html to display the string and also out.println with the appropriate html but with out success. In either case, the page works fine as long as the query string is not in quotes. Only when the query string is in quotes, the field is displayed as blank. If I do a view source on the page, I can see that the value is ""test"".
Here is the syntax that I used.
String savedQuery = (String) session.getValue("QUERY");
<INPUT TYPE="text" NAME="QSTR" SIZE=54 VALUE="<%= savedQuery %>">
*****************
String savedQuery = (String) session.getValue("SQUERYTYPE");
<% out.println("<INPUT TYPE=\"text\" NAME=\"QSTR\" SIZE=54 VALUE=\"" + savedQueryString + "\">";%>
Would appreciate any help on this.
kishore
 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to filter out the double quotes when the user enters the text in the text field. There are many ways you can do this. If you have a form, one way of doing this is using javascript to replace the value the user entered with the same value minus the double quotes on the client side. If you want to use Java, you can use a string manipulation function to filter out the double quotes. For example, you can use the startsWith() and endsWith() methods to see if the last characters are double quotes. Hope that helps!
 
kishore mukkamala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
Looks like the question is misunderstood. I do not want to strip or replace. All I want to do is display the exact string that the user entered in the text field after a search has been done. If the user enters "test me" (with the quotes), I need to display it back the same way the user did with the search results. But with jsp or html, it does not seem to work since the value attribute for input tag is always evaluated to<.....value=""test me"">. These multiple quotes are what is causing the problem. As a result, the value is blanked out in the text field, though it is visible when I do a source view.
If I remove one pair of quotes and output the variable (which contains user's string), the value attribute for the input tag is evaluated to <......value="test me"> and the output is shown as test me (with out quotes) which is not what the user entered.
I can print the same string without any problems exactly the way the user entered. The problem happens only when adding the string in the input tag.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a Java problem - you're generating bad html! The statement print("<input value=\"" + xyz + "\">") will, given a value "abc" (including quotes, xyz = "\"abc\"" produce:
<input value=""abc"">
 
kishore mukkamala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway:
Thanks for the response.
*****************************************************
<input value=""abc"">
The statement print("<input value=\"" + xyz + "\">")
*****************************************************
I agree that this is generating bad html, but is there a way to output the string "abc" (including quotes) inside the text field?? (I am sure there must be - almost all the search engines do that irrespective of the technology). The above example that you quoted just escapes the quotes during evalutation and translates to <input value=""abc""> and will not dump "abc" on the screen. Instead the text field is blanked though you can see it in source.
I just want "abc" (including quotes) to be displayed on the screen.
 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to append double quotes to a value entered in a text field and it seemed to work for me. My example was very simple, but it should work. One thing I did differently was to use single quotes to surround the values of the html attributes.
Here is the code of the text box that displayed the value in double quotes:
<input type='text' name='text1' value='"<%=request.getParameter("text1")%>"'>
[This message has been edited by Jeff Sunder (edited July 17, 2001).]
 
Bhupinder Dhillon
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kishore mukkamala:
I just want "abc" (including quotes) to be displayed on the screen.
[/B]

Escape those quotes with html escape equivalent & q u o t ;
Eg:
out.println("<input type=\"text\" value=\"& q u o t ;Test& q u o t ;\">");
Note: I added spaces in escape word b/c the browsers won't display them otherwise.
[This message has been edited by Bhupinder Dhillon (edited July 17, 2001).]
[This message has been edited by Bhupinder Dhillon (edited July 17, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!