Reputation: 6440
I have the technical question related to the issue as:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 12 13:49:28 CET 2023
There was an unexpected error (type=Not Found, status=404).
JSP file [/admin/project_category/admin/project_category/list.jsp] not found
with accessing the page http://localhost:8080/admin/project_category/list
.
While debugging controller:
@GetMapping("admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new ModelAndView("admin/project_category/list");
modelAndView.addObject("projectList", projectList);
return modelAndView;
}
inside the project, I don't have any duplicated folders:
but using the browser will be another situation:
There's I see I need additional resolver, but in the following project I don't need to use any specific resolvers.
I don't quite understand, why I don't have it twice in similar project.
Can someone tell me, please, what do I need to fix to handle this problem finally? Is it the problem with JSP
files specifically or something?
Thank you in advance for any helpful ideas.
UPD:
After some observation, I see:
if I have the following snippet of code:
@GetMapping("admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new ModelAndView("admin/project_category/list");
modelAndView.addObject("projectList", projectList);
return modelAndView;
}
I'm getting the issue as:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jan 12 13:49:28 CET 2023 There was an unexpected error (type=Not Found, status=404). JSP file [/admin/project_category/admin/project_category/list.jsp] not found
If I add slash in the beginning as:
@GetMapping("/admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new ModelAndView("/admin/project_category/list");
modelAndView.addObject("projectList", projectList);
return modelAndView;
}
I'm getting another issue as:
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "java.util.List.iterator()" because "projectCategory" is null java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "projectCategory" is null
Upvotes: 1
Views: 178
Reputation: 6440
Fri Jan 13 23:16:50 CET 2023 There was an unexpected error (type=Internal Server Error, status=500). Cannot invoke "java.util.List.iterator()" because "projectCategory" is null java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "projectCategory" is null
I needed to change the parameter projectCategory
instead of projectList
:
@GetMapping("/admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView =
new ModelAndView("/admin/project_category/list");
modelAndView.addObject("projectList", projectList);
return modelAndView;
}
as the following:
@GetMapping("/admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new
ModelAndView("/admin/project_category/list");
modelAndView.addObject("projectCategory", projectList);
return modelAndView;
}
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 14 00:01:17 CET 2023 There was an unexpected error (type=Not Found, status=404). JSP file [/admin/project_category/admin/project_category/list.jsp] not found
you need to add slash in the beginning of mapping declaration:
@GetMapping("admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new
ModelAndView("admin/project_category/list");
modelAndView.addObject("projectCategory", projectList);
return modelAndView;
}
as the following:
@GetMapping("/admin/project_category/list")
public ModelAndView projectCategoryList() {
List<Project> projectList = projectServiceImpl.get();
ModelAndView modelAndView = new
ModelAndView("/admin/project_category/list");
modelAndView.addObject("projectCategory", projectList);
return modelAndView;
}
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 14 00:22:21 CET 2023 There was an unexpected error (type=Internal Server Error, status=500). class com.test.application.data.models.Project cannot be cast to class com.test.application.data.models.ProjectCategory (com.test.application.data.models.Project and com.test.application.data.models.ProjectCategory are in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader u/6ef9aa30) java.lang.ClassCastException: class com.test.application.data.models.Project cannot be cast to class com.test.application.data.models.ProjectCategory (com.test.application.data.models.Project and com.test.application.data.models.ProjectCategory are in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader u/6ef9aa30)
I needed to change to the correct type inside list.jsp:
<tbody>
<%
List<ProjectCategory> projectCategory = (List<ProjectCategory>) request.getAttribute("projectCategory");
for (ProjectCategory c : projectCategory)
{
%>
<tr>
<th scope="row"><%=c.getId()%></th>
<td><%=c.getName()%></td>
<td>
<a class="btn btn-success" href="update?id=<%=c.getId()%>" role="button">Edit</a>
<a onclick="return confirm('Are you sure you want to delete it?');" class="btn btn-danger" href="delete?id=<%= c.getId() %>" role="button">Delete</a>
</td>
</tr>
<%
}
%>
</tbody>
to another type of List
as:
<tbody>
<%
List<Project> projectCategory = (List<Project>) request.getAttribute("projectCategory");
for (Project c : projectCategory)
{
%>
<tr>
<th scope="row"><%=c.getId()%></th>
<td><%=c.getName()%></td>
<td>
<a class="btn btn-success" href="update?id=<%=c.getId()%>" role="button">Edit</a>
<a onclick="return confirm('Are you sure you want to delete it?');" class="btn btn-danger" href="delete?id=<%= c.getId() %>" role="button">Delete</a>
</td>
</tr>
<%
}
%>
</tbody>
Upvotes: 0
Reputation: 2999
Try the following:
@GetMapping("admin/project_category/list")
public ModelAndView projectCategoryList(Map<String, Object> model) {
List<Project> projectList = projectServiceImpl.get();
//ModelAndView modelAndView = new ModelAndView("admin/project_category/list");
//modelAndView.addObject("projectList", projectList);
model.put("projectList", projectList);
//return modelAndView;
return new ModelAndView("list");
}
Upvotes: 1