java - JSP not re-instantiating -


this online library website trying make. advanced search can take multiple inputs, start of array of publications remove items don't match user input. works fine first time, array gets shortened correct array. if typed "programming" of publications have programming in title shown. now, if user clicks on "advance search" button again on navbar (as shown in welcome.jsp) , inputs "uml" code perform search uml on shortened array contains results "programming". have put print statement above

searchresult sr = new searchresult(); sr.searchcontains = publications;

(in control servlet) , prints both inputs uml , programming, seems either not create new array publications?

searchresult.jsp:

<c:foreach var="current" items="${sr.searchcontains}"> title: ${current.title} </c:foreach>

controllerservlet.java:

 if (action.equals("advsearch")) {              searchresult sr = new searchresult();              sr.searchcontains = publications;               nextpage = "searchresult.jsp";               string titlestring = request.getparameter("titlestring");               if (!titlestring.equals("")){                  arraylist<publication> toremove = new arraylist<publication>();                  (publication p : sr.searchcontains){                      if (!p.title.contains(titlestring)){                          toremove.add(p);                      }                   }                   sr.searchcontains.removeall(toremove);               }  request.getsession().setattribute("sr", sr);              requestdispatcher rd = request.getrequestdispatcher("/"+searchresult.jsp);              rd.forward(request, response); 

welcome.jsp:

<ul class="nav navbar-nav">         <li class="active"><a href="advancedsearch.jsp">advance search <span class="sr-only">(current)</span></a></li>         </ul> 

advancedsearch.jsp:

<form action="controller" method="post">   <div class="form-group">      <label for="title">title:</label>      <input type="text" class="form-control" name="titlestring">      <input type="hidden" name="action" value="advsearch" />   </div>  <button type="submit" class="btn btn-default">advanced search</button> </form> 

searchresult.jsp:

public class searchresult {     public arraylist<publication> searchcontains = new arraylist<publication>();      public arraylist<publication> getsearchcontains (){         return this.searchcontains;     } } 

found solution, problem in controlservlet

searchresult sr = new searchresult(); sr.searchcontains = publications; 

this means sr.searchcontains same reference publications, main array.


Comments