简体   繁体   中英

How to provide data model for JSP within a JSP in spring mvc

I am facing some issues in providing data model to inner jsp included in jsp itself. I have a controller that points to a jsp ( home.jsp ) which includes another jsp (login_form.jsp) in it self using

<c:import var="data" url="login_form.jsp"/>

Using above method works well but i am not able to bind the data required for login_form.jsp.

so i took second approach, make a controller for login_form and use that controller mapping url to include jsp

<c:import var="data" url="/loginform"/>

Above solution works and also gives the data model required for login_form.jsp, but in this case login_form is available to public via controller which i don't want.

Any help how to fix this ?

This is because the data variable is set in page scope.

If you want to make this work, you have to set the variable in request scope at least. To set your variable in request scope, use the scope attribute on :

<c:import var="data" url="login_form.jsp" scope="request" />

Here's a documentation to know about object scoping in JSP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM