简体   繁体   中英

Cannot access struts action data from nested JSP

I am working for first time with Struts 2 + Spring + Hibernate architecture. I took this project as reference for building it and it works. I can list DB tables in my index.jsp using struts tags, but this does not work from nested JSP loaded into DIV containers inside index.jsp.

index.jsp has a <div class="art-nav"></div> and loads there another jsp using js:

    $(".art-nav").load("./menu.jsp"); 

The same struts tags that work in index.jsp to list DB tables do not work in menu.jsp. I am not sure if the problem is the way I am loading this JSP or if it is necessary to execute some action from Struts 2 before loading menu.jsp...

Basically the JSPs use AJAX and I am adapting them to this architecture and there is where I am facing the problems because of my lack of experience.

Thank you in advance for your help!

You should include the second jsp as follows:

<div class="art-nav">    
    <%@ include file="/WEB-INF/jsp/menu.jsp"%>
</div>

If you load your jsp via javascript the response will not get forwarded to that jsp.

If you really want to load a jsp via javascript you should create a new action (menu.action) that returns a parsed jsp and include it in the existing html. (Though I personally do not really like that technique.)

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