I'm using Java EE for an enterprise application on Glassfish.
I have some xhtml files in WEB-INF to prevent direct URL access. Those files are displayed by a servlet like this:
request.getRequestDispatcher("/WEB-INF/HiddenFile.xhtml").forward(request, response);
The only problem I'm experiencing is that the expression language in those files that references some managed beans is not getting evaluated.
Any help on getting the Expression Language evaluation for those files is greatly appreciated.
Thanks in advance
EDIT
I didn't consider the information useful but since it has been requested here it is.
The page to be displayed, WEB-INF/HiddenFiles/FileA.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>PAGE A</title>
</h:head>
<h:body>
A - #{testBean.testString}
</h:body>
</html>
The extract from the servlet responsible of producing a response:
public class RedirectorServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
if (logic()) {
request.getRequestDispatcher("/WEB-INF/HiddenFiles/fileA.xhtml").forward(request, response);
} else {
request.getRequestDispatcher("/WEB-INF/HiddenFiles/fileB.xhtml").forward(request, response);
}
*other methods including logic()*
}
The web.xml in WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>RedirectorServlet</servlet-name>
<servlet-class>servlet.RedirectorServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RedirectorServlet</servlet-name>
<url-pattern>/RedirectorServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
EL is only evaluated by FacesServlet
in case of Facelets files and by JspServlet
in case of JSP files.
You've mapped the FacesServlet
on /faces/*
. However, your "redirector servlet" isn't forwarding to an URL matching that pattern. So the FacesServlet
won't be invoked and hence the Facelets file with all taglibs and EL on it won't be parsed and executed but just returned like plain text.
You need to change the FacesServlet
mapping from /faces/*
to *.xhtml
, so that it can also be invoked on XHTML files placed in /WEB-INF
which is forwarded by a servlet or filter.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Unrelated to the concrete problem, the term "redirect" is misplaced here. You're here actually performing a forward. And, you should actually be using a servlet filter for the job.