Results 1 to 3 of 3
  1. #1
    banhbaochay is offline Member
    Join Date
    Apr 2010
    Posts
    32
    Rep Power
    0

    Default Retrieve String in textarea

    Hi everybody,
    I have a bit trouble with textarea in JSP. Can you help me to solve it?

    I want to match a word in String retrieve from tag Textarea of page1.jsp
    Java Code:
    <form name="form1" method="POST" action="page2.jsp">
    <textarea name="textarea1" cols=20 rows=3></textarea>
    <input type="submit" value="Click">
    </form>
    So I have this code in page2.jsp:
    Java Code:
    <%
    String str = request.getParameter("textarea1");
    boolean result = str.matches("anh.*");
    out.println(result);
    %>
    I put String "anh dung" in page1.jsp and click button "Click", then page2 display: "true". No problem in this case, but in textarea page1, if I put more than 1 line (ex. line1: anh dung, line2: thanh nam...), page2'll display "false". I don't understand it?

    I try to do something below:
    In page2.jsp, I remove the newline character of String which retrieve from page1, then match it. Page2.jsp change to:
    Java Code:
    StringBuffer strBuffer = new String(request.getParameter("textarea1");
    String str;
    boolean result;
    int loc = strBuffer.indexOf("\n");
    while (loc >= 0) {
    strBuffer.replace(loc, loc + 1, ",");
    loc = strBuffer.indexOf("\n");
    }
    str = new String(strBuffer);
    result = str.matches("anh.*");
    out.println(result);
    But the result's still false.
    Thanks for reading, sorry for my bad English :)

  2. #2
    banhbaochay is offline Member
    Join Date
    Apr 2010
    Posts
    32
    Rep Power
    0

    Default

    Anybody can help me :(.
    Now I'm trying process with javascript sending, but I still want process it in JSP

  3. #3
    banhbaochay is offline Member
    Join Date
    Apr 2010
    Posts
    32
    Rep Power
    0

    Default

    I can solve this problem by using Pattern and Matcher class (not use matches method of String class) and it's perfect. But I don't understand that why?

Similar Threads

  1. Store and Retrieve Problem.
    By MaN-GreaSe in forum New To Java
    Replies: 5
    Last Post: 04-23-2010, 09:50 PM
  2. How to convert a TextArea to a String?
    By Antonioj1015 in forum Java Applets
    Replies: 1
    Last Post: 10-16-2009, 05:23 PM
  3. TextArea Bug?
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 12:37 PM
  4. How to retrieve data from servlet
    By valery in forum Java Servlet
    Replies: 1
    Last Post: 08-06-2007, 08:25 PM
  5. textarea
    By ubuntu in forum AWT / Swing
    Replies: 4
    Last Post: 05-12-2007, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •