Search code examples
javaspringjspviewpartial

Spring Framework: Inserting another JSP file with a JSP file


So I have my Request Path set as mywebsite.com/project/id/12378912?section=data, which maps to a corresponding Controller/Action and returns "project/index.jsp".

Inside index.jsp, I want to check what section-parameter it is and insert the correct PartialView section (but... I want to go to the Controller/Action to process some logic). Is this possible?

I know I can do something like using (jsp:include) and insert another .jsp page, but I want to go to the Controller/Action (of that .jsp page) to run some logic to dynamically generate that .jsp page.

In ASP MVC, we had something similar...

@{ Html.RenderAction("_" + (string)ViewData["projectSection"], "Project", new { id = Model.Id }); }

which was embedded into the master/bigger view container.


Solution

  • <jsp:include page="${request.contextPath}/mvc/project/id/${ project.id }/_data"></jsp:include>
    

    into the correct location on the web page is what I was looking for. This code snippet actually goes to the Controller, processes any logic, and then generates the view --> outputting onto the main/parent page.