java - Does the DispatcherServlet creates new instance of controller and methods inside for each user? -
good day folks. have controller in application:
@controller public class loginsearchcontroller { //list store data resulthtml method list<cars> listcars = null; @autowired private educationwebserviceinterface educationwebservice; //this method render jsp page user , create model resulthtml @requestmapping(value="/search", method=requestmethod.get) public string search(formbackingobjectsearch fbos, model model) { model.addattribute("fbosattributes", fbos); return "search"; } // method name form form object , use fetchcarsbynameservice method // after if found stores in listofserchobjects , after listofserchobjects stores in listform list @requestmapping(value="/result", method=requestmethod.get) public string resulthtml(@requestparam string name, @modelattribute("fbosattributes") formbackingobjectsearch fbos, bindingresult bindingresut, model model) throws exception { listcars = new arraylist<cars>(); list<cars> listofserchobjects = null; listofserchobjects = educationwebservice.fetchcarsbynameservice(dateconvertation(fbos.getname())); model.addattribute("findattributes", listofserchobjects); listcars.addall(listofserchobjects); return "search"; } //this method fetch data listform make excel document form list @requestmapping(value="/result.xls", method=requestmethod.get) public string resultxls(model model) throws exception { if(listcars == null || listcars.size() == 0) { throw new nullpointerexception("arraylist<formdate> formdatelist empty list"); } else { model.addattribute("findattributesxls", listform); } return "xlspage"; } }
what happens in controller:
user goes on search
page fill name of car find(in case) , after click button find
--> request goes /result
. resulthtml
method invoke fetchcarsbynameservice
service layer fetch data corresponding particular name listofserchobjects
, render on jsp page. after when listofserchobjects
have data fetchcarsbynameservice
add data other list listcars
.
--> next step, when data rendered on jsp page there button appears save excel
, happens: when user click button(if user want too) goes /result.xls
and take data from listcars
save in excel file.
i'm curious if multiple users work on same jsp page form different computers in web application, how listcars
behave. i'm scary store last data witch extracted database , if user1 want render in excel file have data user2 if user2 make search last. think??? give me please advice. thank you
listcars
corrupted , may throw concurrentmodificationexception
sporadically.
below workarounds issue.
make
listcars
local variable.or
annotate
controller
@scope("session")
here excellent blog describes scope
of controller
, pros , cons.
Comments
Post a Comment