title: how to use or call java class in servlet and display the result to jsp
body: <p>I am able to pass the searchterm in NewFile.jsp to HelloWorld servlet and display the result in wecome jsp.  I have another program wrote in the new java class.I do not know how to pass the searchterm to the java class. so as to run the program.</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="2.4" 
      xmlns="http://java.sun.com/xml/ns/j2ee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Hello&lt;/servlet-name&gt;
      &lt;servlet-class&gt;HelloWorld&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Hello&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/HelloWorld&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>NewFile.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
      "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
          &lt;title&gt; My JSP page &lt;/title&gt;
      &lt;/head&gt; 
      &lt;body&gt;      
          &lt;form method="post" action="HelloWorld"&gt;            
               Please enter a Keyword &lt;br&gt;
              &lt;input type="text" name="searchTerm"size="20px"&gt;
              &lt;input type="submit" value="submit"&gt;                        
          &lt;/form&gt;     
      &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>welcomepage.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%String X = (String)request.getAttribute("searchTerm");%&gt;
  
   The search word is&lt;%=X %&gt;
  
  &lt;%-- welcom &lt;%=request.getAttribute("searchTerm")%&gt; --%&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>servlet: HelloWorld.java</p>
  
  <pre><code>import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.PrintWriter;
  
  public class HelloWorld extends HttpServlet { 
    protected void doGet(HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException 
    {
      doPost(request,response);
  
    }
  
    protected void doPost(HttpServletRequest request, 
            HttpServletResponse response) throws ServletException, IOException 
        {
  
  
      // ..........reading the user input
      String searchTerm= request.getParameter("searchTerm");  
    request.setAttribute("searchTerm",searchTerm);
    request.getRequestDispatcher("welcomepage.jsp").forward(request, response);
  
  
    }  
  
    }
  </code></pre>
  
  <p>the other javascript: 
  Myprogram.java</p>
  
  <pre><code>public class ParameterPy {
  
  public static void main(String a[]){
  try{
  
  String searchTerm="google";
  
  ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","D://program.py",""+searchTerm);
  Process p = pb.start();
  
  BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));
  
  System.out.println(".........start   process.........");  
  String line = "";     
  while ((line = bfr.readLine()) != null){
      System.out.println("Python Output: " + line);
  }
  System.out.println("........end   process.......");
  
  
  }catch(Exception e){System.out.println(e);}
  }
  }
  </code></pre>
  
  <p>How do I link the variable searchterm in Myprogram.java with the variable in  HelloWorld.java (replace the "google" to the real time user input search term) since the  HelloWorld.java is a servlet can display to the jsp.</p>