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
Joined: Jul 16, 2001
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.
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"">
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jul 16, 2001
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.
Joined: Jun 26, 2001
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).]
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).]