Spring MVC: enabling JSP inside the view (JSP is installed next to the view, so it is not available to the external controller)?

I created the view and it works well, but now I need to include another JSP inside the page.

Given that my views are installed in the WEB-INF / Views protected area (therefore, it is not available in my resource directory, where my imgs, css are located)

I tried using

<%@ include file="/views/shared/items/NewItem.jsp" %> 

And he always gives me FileNotFound, taking into account that my NewItem.jsp is installed with my other views (i.e. it is NOT accessible via regular routes, but controlled by controllers), how can I include JSP files that are installed next to my view

If I take out the "include file", my view is displayed without problems.

I'm sure something is missing here?

Thanks in advance

+4
source share
2 answers

If NewItem.jsp is located in /WEB-INF/views/shared/items/NewItem.jsp , then you should use this path when it entered it:

 <%@ include file="/WEB-INF/views/shared/items/NewItem.jsp" %> 
+14
source

Better for the user.

 <jsp:include /> 

instead

 <%@ include /> 

and send a request to the controller and the controller to process the view

Sending a request to contoller

  <jsp:include page="${request.contextPath}/newItem"></jsp:include> 

controller

 @RequestMapping(method = RequestMethod.GET, value = "newItem") public String newItem(Model model) { return "shared/items/NewItem"; } 
+4
source

Source: https://habr.com/ru/post/1398600/


All Articles