Good day folks. I have Controller in my application:
@Controller
public class LoginSearchController {
//List to store data from resultHTML method
List<Cars> listCars = null;
@Autowired
private EducationWebServiceInterface educationWebService;
//This method render jsp page for user and create model for resultHTML
@RequestMapping(value="/search", method=RequestMethod.GET)
public String search(FormBackingObjectSearch fbos, Model model) {
model.addAttribute("fbosAttributes", fbos);
return "search";
}
// This method get name form form back object and use it for fetchCarsByNameService method
// After if something found it stores it in listofSerchObjects and after listofSerchObjects stores it 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 from listForm to make Excel document form the 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 is empty list");
} else {
model.addAttribute("findAttributesXls", listForm);
}
return "xlspage";
}
}
What happens in controller:
User goes on Search page fill name of Car he would like to find(in my case) and after click button FIND
--> Request goes to /result. This resultHTML method invoke fetchCarsByNameService from service layer to fetch data corresponding to particular name to listofSerchObjects and render it on jsp page. After when listofSerchObjects have data from fetchCarsByNameService it will add all data to other list listCars .
--> Next step, when all data was rendered on jsp page there is button appears SAVE AS EXCEL, what happens: when user click this button(if user want too) it goes to /result.xls AND TAKE ALL THE DATA FROM listCars to save it in Excel file.
I'm very curious if multiple users will work on the same jsp page form different computers in my web application, how my listCars will behave. I'm scary that it will store last data witch was extracted from DataBase and if user1 want to render it in Excel file that he will have data from user2 if user2 would make search last. What you think??? Give me please advice. Thank you