Juan Fu wrote:
>
> Hi,
>
>    I am currently using JSP to write a HTML page. I am encountering a string
> problem. Here is my code.
>
> --------test.htm ----------------
>    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
> <head>
>         <title>Untitled</title>
> </head>
>
> <body>
> <form name=test method=post action="test1.jsp">
> <input type=text name=txt>
> <input type=submit value="Submit">
> </form>
> </body>
> </html>
> ----------------------------------------
>
> ---------- test1.jsp --------------
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>
> <html>
> <head>
>         <title>Untitled</title>
> </head>
>
> <body>
> <% String test=request.getParameter("txt");
>    System.out.println(test);
>
>    %>
> <form name="test1">
> <input type=text name="txttest1" value="<%=test%>">
> </form>
>
> </body>
> </html>
>
> If user entered a string like this:
>    He said:"I saw you yesterday."
>
> Then when user clicks the submit button, only He said: is displayed in the
> test1.jsp page. Can anyone tell me how to make the string contains with
> white space, double quote and single quote work?

You need to convert all quote characters in the value to the corresponding
HTML character entities: single quotes to "&#39;" and double quotes to "&#34;".

If you download my JSP book examples, you can use the included StringFormat
utility class to convert the string, like this:

  <%@ page import="com.ora.jsp.util.StringFormat" %>
  ...
  <input type=text name="txttest1"
    value="<%= StringFormat.toHTMLString(test) %>">

All book examples are available here:

  <http://TheJSPBook.com/>

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to