简体   繁体   中英

Request Dispatcher to access pages in WEB-INF folder?

according to netbeans e commerce tutorial. https://netbeans.org/kb/docs/javaee/ecommerce/page-views-controller.html#view there are 4 pages include header & footer placed in WEB-INF folder but they can access it via controllerservlet (RequestDispatcher). i've googling and found a lot of questions about how to access/redirect to pages in WEB-INF folder but the result can't access pages(xhtml,jsp,etc) in WEB-INF folder. my questions is 1. could i access pages in WEB-INF folder with RequestDispatcher (with JSF 2.X) ? 2. how to access pages in WEB-INF with JSF 2.X ?

A simple solution is to create a page that is outside WEB-INF. Let us call this page placeHolder.xhtml

If you know which page fragment you wish to show from within WEB-INF, then make it available via a bean. Let us say the following method returns the page that has to be included

#{mybean.pageToInclude}

Now, in the placeHolder.xhtml file, use the ui:include tag to include page that is present under WEB-INF

placeHolder.xhtml
...
  <ui:inlucde src="#{mybean.pageToInclude}"/>

This way you can get code within WEB-INF to be made available in a page that is outside of it.

There are other techniques like writing a ResourceHandler to locate view resources under different locations that you can use too.

Hope that helps.

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