简体   繁体   中英

Dynamically include HTML in JSP

I want to include html pages dynamically in a JSP page. I'm fetching the html url from HTML forder and using struts2 to pass the value to JSP page but I'm unable to do this on JSP using either jsp:include or @include tags.

For Example, I have variable html Url like /somepath/variablehtmlname.html in my struts action property. I want to use this path to include the actual html files located at /somepath location.

<%@ include ... %> is evaluated when your JSP pages are compiled and have no access to request variables (like Struts 2 action properties.) Use <c:import /> or <s:include /> instead, which include content on a per-request basis. <jsp:include /> should also work, but (as @BalusC requested) without the code, we can't tell why it doesn't.

Reusing Content in JSP Pages

I agree with the first answer (BobG). You can also simply have the JSP page directly serve up an http forwardTo using the refresh tag, where the servlet writes the new url location to a session variable : <meta http-equiv="refresh" content="0; URL=<%=htmlSessionLink>" />**

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