大家好。
请帮我。我有应用程序和简单的控制器,它们从数据库中搜索数据,当在数据库中创建数据时,它也会在浏览器中呈现它们,当数据出现在页面上时,Render in EXCEL
如果用户想要在 Excel 文件中呈现它,也会出现按钮。这是控制器:
@Scope("session")
@Controller
public class SearchController {
//Apache log4j logger for this controller to bring info to console of executing inside of this controller
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(SearchController.class);
@Autowired
private EducationWebServiceInterface educationWebService;
List<FormDate> listForm = null;
@ModelAttribute("listOfDates")
public List<Date> prepareModelDate() {
List<Date> listOfDates = educationWebService.fetchAllDatesService();
return listOfDates;
}
@ModelAttribute("listOfNames")
public List<String> prepareModelNames() {
List<String> listOfNames = educationWebService.fetchAllInstitutionNamesService();
return listOfNames;
}
@ModelAttribute("listOfTypes")
public List<String> prepareModelTypes() {
List<String> listOfTypes = educationWebService.fetchAllInstitutionTypesService();
return listOfTypes;
}
@RequestMapping(value="/search", method=RequestMethod.GET)
public String search(FormBackingObjectSearch fbos, Model model) {
model.addAttribute("fbosAttributes", fbos);
return "search";
}
@RequestMapping(value="/result", method=RequestMethod.GET)
public String resultHTML(@RequestParam String particularDate,
@RequestParam String nameOfInstitution,
@RequestParam String typeOfInstitution,
@ModelAttribute("fbosAttributes") @Validated FormBackingObjectSearch fbos,
BindingResult bindingResult,
Model model) throws Exception {
ValidatorSearch validatorSearch = new ValidatorSearch();
validatorSearch.validate(fbos, bindingResult);
if(bindingResult.hasErrors()) {
return "search";
}
listForm = new ArrayList<FormDate>();
//Case 1:
if(!fbos.getParticularDate().equals("") && !fbos.getNameOfInstitution().equals("") && fbos.getTypeOfInstitution().equals("")) {
listForm = educationWebService.fetchByDateAndNameService(DateChangerUtils.dateConvertation(fbos.getParticularDate()), fbos.getNameOfInstitution());
model.addAttribute("findAttributes", listForm);
//Case 2:
} else if(!fbos.getParticularDate().equals("") && fbos.getNameOfInstitution().equals("") && !fbos.getTypeOfInstitution().equals("")) {
listForm = educationWebService.fetchByDateAndTypeService(DateChangerUtils.dateConvertation(fbos.getParticularDate()), fbos.getTypeOfInstitution());
model.addAttribute("findAttributes", listForm);
//Case 3:
} else if(!fbos.getParticularDate().equals("") && fbos.getNameOfInstitution().equals("") && fbos.getTypeOfInstitution().equals("")) {
listForm = educationWebService.fetchByDateService(DateChangerUtils.dateConvertation(fbos.getParticularDate()));
model.addAttribute("findAttributes", listForm);
//Case 4:
} else {
throw new Exception("Exception occurs because it's not correspond to any case in controller");
}
return "search";
}
@RequestMapping(value="/result.xls", method=RequestMethod.GET)
public String resultXLS(Model model) throws NullPointerException {
if(listForm == null || listForm.isEmpty() == true) {
throw new NullPointerException("Can not create Excel file because no data to create from");
} else {
model.addAttribute("findAttributesXls", listForm);
}
return "xlspage";
} //End of the resultXLS(..) method
} //End of the class
现在让我们在浏览器中使用选项卡:
我的问题是,当我将浏览器选项卡一中的渲染数据保存为 Excel 文件一次并在浏览器选项卡二中打开新选项卡时,再次在选项卡二中查找并呈现一些不同的数据,然后返回选项卡一个在我的浏览器中,然后再次尝试将表一中的相同数据保存为 Excel 文件我从表二中获取数据(我渲染的最新数据),但我想从
我在 Servlet 之前学习的标签一中获取旧数据,并且对会话同步非常感兴趣. 这是我在我的情况下的作品在 servlet 中,它可以通过以下方式到达:HttpSession session = request.getSession();
我如何在 Spring MVC 中做到这一点???它会解决我的问题吗?请给我建议。
谢谢大家。一切顺利。