Akash
Akash

Reputation: 748

Facelets equivalent of <jsp-file> servlet mapping

Note - This question might have been answered earlier but I am not able to find any note on this. hence asking!

Background - I am working on a legacy JSF application which uses JSP as view technology. Now since we have decided to move to JSF 2.2/2.3, we are also changing the JSP pages to facelets.

Issue - In the web.xml, we have following mapping -

<servlet>
   <servlet-name>dummyframe</servlet-name>
   <jsp-file>/WEB-INF/dummyframe.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>dummyframe</servlet-name>
    <url-pattern>dummyframe</url-pattern>
<servlet-mapping>

We have converted jsp file to facelet file but not sure how to handle this jsp-file mapping.

We are planning to write java classes which will redirect to facelet page. In this case, the mapping will be -

<servlet>
   <servlet-name>dummyframe</servlet-name>
   <servlet-class>xxx.xxxx.dummyframe</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>dummyframe</servlet-name>
    <url-pattern>dummyframe</url-pattern>
<servlet-mapping>

The questions I have - 1) Is this a good alternative? 2) Is there any other alternative available without writing java classes?

Upvotes: 2

Views: 250

Answers (1)

krokodilko
krokodilko

Reputation: 36107

1) Is this a good alternative?

Yes, but I think it would be better to implement redirection in a filter instead of a servlet class.


2) Is there any other alternative available without writing java classes?

Leave dummy servlet mapping in web,xml as is and put into /WEB-INF/dummyframe.jsp this:

<html>
  <head>
    <meta http-equiv="Refresh" content="0; URL=mynewdummyfile.jsf">
  </head>
</html>

or this:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
  <body>
     <c:redirect url="mynewdummyfile.jsf"/>
  </body>
</html>

or this:

<%@ page import = "java.io.*,java.util.*,javax.servlet.http.HttpServletResponse" %>

<html>
   <body>
      <%
         response.sendRedirect("mynewdummyfile.jsf");
      %>
   </body>
</html>

or this:

<%@ page import = "java.io.*,java.util.*,javax.servlet.http.HttpServletResponse" %>

<html>
   <body>
      <%
         response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
         response.setHeader("Location", "mynewdummyfile.jsf"); 
      %>
   </body>
</html>

or this:

<%@ page import = "javax.servlet.ServletContext" %>

<html>
   <body>
      <%
        ServletContext sc = getServletContext();
        sc.getRequestDispatcher("/WEB-INF/mynewdummyfile.jsf").forward(request, response);
      %>
   </body>
</html>

Upvotes: 1

Related Questions