JSP Servlet Combination
<p>I have JSP page named SearchBoxNew.jsp which i added under Welcome-File tag of Web.xml</p>

<p>This page basically has one search box in which when i type something and hit enter i will call another Servlet "SolrServlet1.java", this basically query some file storage and add the response object to a HTTPRequest and redirects to SearchBoxNew.jsp using <strong>"dispatcher.forward(request, response);"</strong> </p>

<p>But unfortunately when i enter the text and press enter it is telling me HTTP <strong>Status 404 - /SearchBoxcComp/SearchBox.jsp</strong></p>

<p>And the URL is like this <strong><a href="http://localhost:8080/SearchBoxcComp/hello" rel="nofollow">http://localhost:8080/SearchBoxcComp/hello</a></strong> where /hello is a URL mapping for servlet.</p>

<p>Here is my web.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
  &lt;display-name&gt;SearchBoxcComp&lt;/display-name&gt;
  &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;SearchBoxNew.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;SolrServlet1&lt;/servlet-name&gt;
    &lt;servlet-class&gt;Servlets.SolrServlet1&lt;/servlet-class&gt;
  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;SolrServlet1&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;

  &lt;servlet&gt;
    &lt;servlet-name&gt;SearchBoxNew&lt;/servlet-name&gt;
    &lt;jsp-file&gt;/SearchBoxNew.jsp&lt;/jsp-file&gt;
  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;
&lt;servlet-name&gt;SearchBoxNew&lt;/servlet-name&gt;
&lt;url-pattern&gt;/SearchBoxNew&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;


&lt;/web-app&gt;
</code></pre>

<p>Can somebody tell me what i am missing or how can i land in a search page again after pressing enter?</p>

<pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
&lt;%@ page import ="org.apache.solr.common.*" %&gt;
&lt;%@ page import = "java.util.*" %&gt;
&lt;%@ page import = "org.apache.solr.client.solrj.response.*" %&gt;
&lt;%@ page import="org.apache.solr.client.solrj.response.FacetField.Count" %&gt;
&lt;%@ page import = "java.util.List" %&gt;
&lt;%@ page import = "com.google.gson.*" %&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;body&gt;
&lt;h1&gt;Search Component&lt;/h1&gt;

        &lt;div&gt;
          &lt;form id="formsearch" name="formsearch" method="post" action="/SearchBoxcComp/hello"&gt;
          &lt;span&gt;&lt;input name="searchWord" class="editbox_search" id="editbox_search" maxlength="120" value="" type="text"  style="width:180px; height:20px"/&gt;&lt;/span&gt;
            &lt;input name="button_search" value="search" type="submit" name="submit"/&gt;
            &lt;div class="clr"&gt;&lt;/div&gt;
            &lt;%! public QueryResponse QryRspnsMain; %&gt;
            &lt;%
            if(request.getParameter("submit") != null){
            //String paramValue = request.getAttribute("SearchResult");
            //System.out.println(paramValue);
            //out.println("&lt;tr&gt;&lt;td&gt;" + paramValue + "&lt;/td&gt;&lt;/tr&gt;");
            QueryResponse QryRspnsMain = (QueryResponse)request.getAttribute("SearchResult");
            Gson gson= new Gson();
            SolrDocumentList results = QryRspnsMain.getResults();
            // Get the Json Object 
            //*************String Jresponse= gson.toJson(results);

            Iterator&lt;SolrDocument&gt; litr = results.iterator();
            String res = gson.toJson(results);
                for (int i = 0; i &lt; results.size(); ++i) {
                    out.print("&lt;li&gt;" + res);
                }
             }
            %&gt; 


          &lt;%
          if(request.getParameter("submit") != null){
              QueryResponse QryRspnsMain = (QueryResponse)request.getAttribute("SearchResult");
                Gson gson= new Gson();
                SolrDocumentList results = QryRspnsMain.getResults();
                List&lt;FacetField&gt; facetList = QryRspnsMain.getFacetFields();
                Iterator&lt;FacetField&gt; itr = facetList.iterator();
                while(itr.hasNext()) {
                    FacetField facetField = itr.next();
                    List&lt;Count&gt; facvalue = facetField.getValues();
                    for(int i=0; i&lt;facvalue.size(); i++){
                         System.out.println(facvalue.get(i));
                         out.print("&lt;li&gt;&lt;a href= \"/SearchBoxcComp/facetServlet?facetFiled=\"" + facvalue.get(i) + "&amp;catlevel=" + facetField.getName());
                         }
                }
          }
           %&gt;
                &lt;/form&gt;
        &lt;/div&gt;

&lt;/body&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>Servlet:</strong></p>

<pre><code>package Servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;

/**
 * 
 */



/**
 * Servlet implementation class SolrServlet
 */

public class SolrServlet1 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public SolrServlet1() {
        super();
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String searchWord = request.getParameter("searchWord");
        RequestDispatcher dispatcher = getServletConfig ( ) .getServletContext ().getRequestDispatcher("/SearchBox.jsp");
        //if(searchWord == "" || searchWord == null ){
        try {
            QueryResponse SearchResult = searchQuery(searchWord);
            //String SearchResult = "Avinash Upadhya is Here";
            request.setAttribute("SearchResult", SearchResult);
            dispatcher.forward(request, response);
        } catch (SolrServerException e) {
            e.printStackTrace();
        } 

    }

    private static QueryResponse searchQuery(String search) throws SolrServerException{
        HttpSolrServer server =new HttpSolrServer("http://localhost:8983/solr");
        server.setParser(new XMLResponseParser());
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        query.setFacet(true);
        query.setFacetMinCount(1);
        query.addFacetField("manu");
        query.setStart(0); 
        //String SolrQuery;
        if(search != ""){
            query.addFilterQuery("name:" + search + "OR description: " + search);

        }
            QueryResponse response = server.query(query);
            //SolrDocumentList results = response.getResults();

            return response;

    }

}
</code></pre>