我有通过两个句柄重定向到视图的场景,在第一个句柄中我使用了@RedirectAttribute
并使用了它的方法addFlashAttribute
。
如果我的属性值(String)没有空格或特殊字符,但是空格和特殊字符不起作用,这可以正常工作。
@RequestMapping(value="/addCategory")
public String addCategory(@ModelAttribute("category") Category category ,
@RequestParam int access,RedirectAttributes redirectAttributes , Model model){
System.out.println();
if(categoryService.isCategoryExist(category).equals("category_not_exist")){
categoryService.addCategory(category);
//redirectAttributes.addAttribute("addedCategoryName", category.getCategoryName());
System.out.println("isCategoryAdded YES " +category.getCategoryName().trim());
System.out.println("Category Name "+category.getCategoryName().trim());
redirectAttributes.addFlashAttribute("isCategoryAdded", "yes");
redirectAttributes.addFlashAttribute("addedCategoryName", category.getCategoryName().trim());
}
else{
//redirectAttributes.addAttribute("existCategoryName", category.getCategoryName());
System.out.println("isCategoryAdded NO ");
System.out.println("Category Name "+category.getCategoryName().trim());
redirectAttributes.addFlashAttribute("isCategoryAdded", "no");
redirectAttributes.addFlashAttribute("addedCategoryName", category.getCategoryName().trim());
}
System.out.println();
System.out.println("addedCategoryName ********* "+category.getCategoryName().trim());
System.out.println();
redirectAttributes.addAttribute("paramCategoryId", category.getCategoryId());
redirectAttributes.addAttribute("paramCategoryName", category.getCategoryName());
redirectAttributes.addAttribute("paramParentCategoryId", category.getParentCategoryId());
redirectAttributes.addAttribute("paramMovement", "backward");
redirectAttributes.addAttribute("parentCategoryId", category.getCategoryId());
redirectAttributes.addAttribute("access", access);
/*redirectAttributes.addAttribute("parentCategoryId", category.getParentCategoryId());*/
return "redirect:/Category/categories";
}
在View JSP中
<c:choose>
<c:when test="${ isCategoryAdded eq 'yes'}">
<div class="successMessage">Category '${addedCategoryName }' added successfully.</div>
</c:when>
<c:when test="${ isCategoryAdded eq 'no'}">
<div class="errorMessage">Category '${addedCategoryName }' already exist.</div>
</c:when>
</c:choose>
仅当类别名称包含空格和特殊字符
时才会出现问题如何解决?
谢谢。