Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How servlet can populate jsp/html textarea?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How servlet can populate jsp/html textarea?

    Hi, I have been working in this issue for sometime, but have been stuck in this step for a while. I searched a lot in the internet, read many tutorials and question/answers and now I am totally confused! Hence I am asking this question.

    I have to develop a html/jsp GUI which will calculate the difference of two XMLs entered in two textareas and the result will be populated in the result textarea. Very much similar to XDiff or KDiff applications. GUI will pass the XML1 and XML2 to servlet and servlet will pass the difference to the GUI. I am stucking at the last step - how servlet will populate the result textarea of the html/jsp?

    Also my GUI is multi frames and hence has different source files for each of them. Sample code is as follows -

    1. XML1.html
    HTML Code:
    <form name="xml1">
    XML 1:<br />
      <textarea name="xml1text" id="comments" style="width:100%;height:95%;background-color:#D0F18F;">
      Text Area 1!
      </textarea><br />
    </form>
    2. XML2.html
    HTML Code:
    <form name="xml2">
    XML 2:<br />
      <textarea name="xml2text" id="comments" style="width:100%;height:95%;background-color:#D0F18F;">
      Text Area 2!
      </textarea><br />
    </form>
    3. XML3.html
    HTML Code:
    <script language="javascript" type="text/javascript">
    function mysubmit()
    {
    	xml3.text1.value=window.parent.left.xml1.xml1text.value;
    	xml3.text2.value=window.parent.right.xml2.xml2text.value;
    }
    </script>
    <form action="/servlet/XMLDiffServlet" name="xml3" method="post">
    XML 3:<br />
      <textarea name="resulttext" id="comments" style="width:100%;height:90%;background-color:#D0F18F;">
      </textarea><br />
      <input type="submit" value="Submit" onClick="javascript:mysubmit()"/>
      <input type="button" value="Clear" />
      <input type="hidden" name="text1" />
      <input type="hidden" name="text2" />
     </form>
    4. XMLDiff.html
    HTML Code:
    <html>
     <head>
      <title>XML Diff</title>
    </head>
    <form name="xmldiff" method="post">
     <frameset rows="50%,50%">
       <frameset cols="50%,50%">
         <frame name="left" src="XML1.html">
         <frame name="right" src="XML2.html">
       </frameset>
       <frame name="bottom" src="XML3.html">
     </frameset>
    </html>
    5. XMLDiffServlet.java
    What should I do here so that the result can be thrown in the XML3's result textarea?

    If it is not possible in html, is it possible to do the same in jsp? Somebody is saying yes, it's possible in html, somebody is saying no. Sobody is suggesting javabeans and somebody is suggesting ajax. I am totally clueless!

    I am sure I have to use req.getRequestDispatcher(), but can it populate the client textarea?

    Please help me out.

    Thanks


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How servlet can populate jsp/html textarea?

    There are quite a few ways to accomplish your need. Some possibilities include a) have the results stored on the server with a specified name and have the results page the results given a paramater name (using GET or POST) - how the results are stored could be in the file system as a temp file (or permanent file) or in a database if you wish to keep the results for later querying b) Place the results in the session with a specified name and have the results page retrieve the session data to display it c) using AJAX, pass the queries to the servlet, retrieve the results, and have javascript populate a textarea with the results. There's most likely other ways, and each way has different ways to implement. I am partial to the AJAX method, but that's just me. I'd say choose one and go for it.

Similar Threads

  1. Jsp Servlet problem with getting parameter vaules from another jsp page
    By venkat_tk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: February 25th, 2013, 02:51 AM
  2. Displaying multiple images using servlet or JSP into html table
    By rajeshraj in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 1st, 2012, 12:21 PM
  3. HTTP post to html servlet
    By Mith in forum Java Theory & Questions
    Replies: 1
    Last Post: October 23rd, 2012, 11:18 AM
  4. Question About servlet and HTML
    By kurt-hardy in forum Java Theory & Questions
    Replies: 5
    Last Post: January 14th, 2011, 09:25 PM
  5. JSP N HTML SIMPLE PROGRAM
    By jugalrockz in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: January 12th, 2011, 11:19 AM