title: Include the content of a jsp file in servlet
body: <p>I need to include the content of a jsp file in my servlet. I tried this.</p>
  
  <pre><code>out_str = "&lt;jsp:include page=\"jsp/agentMenu.jsp\"/&gt;";
  </code></pre>
  
  <p>Here out_str is a String type variable.</p>
  
  <p>But this doesn't work.</p>
  
  <p>Edited: I am using a post request and get the response. According to that result displaying content will be different.</p>
  
  <pre><code>private void initCall(String urlParameters) {
      String result = "";
  
      try {
          //result = sendPostRequest(urlParameters);
          result = "0#04#Succesfully Login";
          System.out.println(result);    //for debugging
          String[] out_array = splitResult(result);
  
          if (Integer.parseInt(out_array[0]) == 0) {    //success
              System.out.println("SUCCESS");
              switch (Integer.parseInt(out_array[1])) {
                  case 1:
                      out_str = "&lt;html&gt;\n"
                              + "&lt;body align=\"center\"&gt;\n"
                              + "&lt;center&gt;&lt;h2&gt;RobiCash&lt;/h2&gt;\n"
                              + "&lt;p&gt;Invalid PIN&lt;p&gt;&lt;/center&gt;\n"
                              + "&lt;a href=\"jsp/login.jsp\"&gt;Exit&lt;/a&gt;"
                              + "&lt;/body&gt;\n"
                              + "&lt;/html&gt;";
  
                      break;
                  case 2:
                      out_str = "&lt;html&gt;\n"
                              + "&lt;body align=\"center\"&gt;\n"
                              + "&lt;center&gt;&lt;h2&gt;RobiCash&lt;/h2&gt;\n"
                              + "&lt;p&gt;Invalid Mobile Number&lt;p&gt;&lt;/center&gt;\n"
                              + "&lt;a href=\"jsp/login.jsp\"&gt;Exit&lt;/a&gt;"
                              + "&lt;/body&gt;\n"
                              + "&lt;/html&gt;";
                      break;
                  case 3:
                      out_str = "&lt;html&gt;\n"
                              + "&lt;body align=\"center\"&gt;\n"
                              + "&lt;center&gt;&lt;h2&gt;RobiCash&lt;/h2&gt;\n"
                              + "&lt;p&gt;System Error&lt;p&gt;&lt;/center&gt;\n"
                              + "&lt;a href=\"jsp/login.jsp\"&gt;Exit&lt;/a&gt;"
                              + "&lt;/body&gt;\n"
                              + "&lt;/html&gt;";
                      break;
                  case 4:  //Agent
                      System.out.println("AGENT");
                      //out_str.concat("&lt;%@ include file=\"jsp/agentMenu.jsp\" %&gt;");
                      out_str =  &lt;jsp:include page="jsp/agentMenu.jsp" /&gt;;
  
  
                      /*out_str = "&lt;html&gt;\n"
                              + "&lt;body align=\"center\"&gt;\n"
                              + "&lt;h2&gt;RobiCash&lt;/h2&gt;\n"
                              + "&lt;h3&gt;Agent Main Menu&lt;/h3&gt;\n"
                              + "&lt;table align=\"center\"&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;1:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_2.htm\"&gt;Top-Up/Recharge (P2)&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; \n"
                              + "&lt;tr&gt;&lt;td&gt;2:&lt;/td&gt;&lt;td&gt;&lt;a href=\"jsp/billPayment.jsp\"&gt;Bill Payment&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;3:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_2.htm\"&gt;Bill Check&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;4:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_3.htm\"&gt;Cash IN (P2)&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;5:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_4.htm\"&gt;Cash OUT (P2)&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;6:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_5.htm\"&gt;Customer Registration&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;6:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_6.htm\"&gt;My Balance&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;7:&lt;/td&gt;&lt;td&gt;&lt;a href=\"agent_7.htm\"&gt;More&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;tr&gt;&lt;td&gt;8:&lt;/td&gt;&lt;td&gt;&lt;a href=\"jsp/login.jsp\"&gt;Exit&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;\n"
                              + "&lt;/table&gt;\n"
                              + "&lt;/body&gt;\n"
                              + "&lt;/html&gt;\n";*/
                      break;
                  case 5:       //DSR
                      break;
                  case 6:      //Distributor
                      break;
                  case 7:      //Master Distributor
                      break;
                  default:
                      break;
              }
          }  else {      //fail
  
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      response = ServletActionContext.getResponse();
      response.setContentType("text/html");
      PrintWriter printWriter = null;
      try {
          printWriter = response.getWriter();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      StringBuffer _bf = new StringBuffer();
  
      _bf.append(out_str);
      printWriter.write(_bf.toString());
      printWriter.flush();
      printWriter.close();
  }
  </code></pre>
  
  <p>Any suggestions would be appreciated.</p>
  
  <p>Thank you in advance</p>