title: Call JSP from Plain Java application and get response back to it
body: <p>I have a Java file which contains main method. I want to call a JSP page from that java file, which will call another java file and get the result back to my main Java file. The second java file will get results from database.</p>
  
  <p><strong>Flow</strong></p>
  
  <p><strong><em>Main Java class</strong> &lt;---> <strong>Jsp</strong> &lt;----> <strong>Another Java class</em></strong></p>
  
  <p>My Work (Edit):</p>
  
  <p>Main Java file:</p>
  
  <pre><code>  public String someMethod() throws Exception 
    {
          HttpClient client = new DefaultHttpClient();;
          HttpEntity httpEntity = null;
          String result=null;
  
          HttpPost method = new HttpPost("url to jsp");
          method.setHeader("Content-Type","application/xml");
          int statusCode = 0;
          try
          {
              List&lt;NameValuePair&gt; urlParameters = new ArrayList&lt;NameValuePair&gt;();
              urlParameters.add(new BasicNameValuePair("parameterName1", "value"));
              urlParameters.add(new BasicNameValuePair("parameterName2", "value"));
              method.setEntity(new UrlEncodedFormEntity(urlParameters));
              HttpResponse httpResponse = client.execute(method);
              httpEntity = httpResponse.getEntity();
              statusCode = httpResponse.getStatusLine().getStatusCode(); 
              if (statusCode == HttpStatus.SC_OK) 
              {
                  //do some work
              } 
              else 
              {
                  //do some work
              }
              return statusMessage;
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
    }
  </code></pre>
  
  <p>My jsp :</p>
  
  <pre><code>&lt;%
     String parameter1 = (request.getParameter("parameterName1"));
     String parameter2 = (request.getParameter("parameterName2"));
  %&gt;
  </code></pre>
  
  <p>By this method the Jsp is been called, but I am not getting parameter values in the jsp file (getting null values). But if I append parameters  in the url itself (another method called as Url Rewriting), I get those values in the jsp file. Am I doing anything wrong? I want to get those parameter values by the method I have provided in the code. can anybody help?</p>