3

We have a JSF2.0 application deployed in weblogic-10.3.4 , we have a requirement to give a user generic url ,say (http://web/apply?7777 ) . When user access this page ,based on query string value , user will be re-directed to client specific page,which can be one of 10 different pages.

So one approach is to have a apply.jsf page ,which has got a pre-render event ,which will re-direct the user to different page based on query string,

Is there any other better approach? not to have apply.xhtml.

Note: In web.xml ,we defined pageNotFound.xhtml in case if the page is not found.

user684434
  • 1,165
  • 2
  • 19
  • 39

1 Answers1

1

You could use a simple servlet filter for this.

@WebFilter("/apply")
public class ApplyFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        String queryString = request.getQueryString();
        String redirectURL = determineItBasedOnQueryString(queryString);

        if (redirectURL != null) {
            response.sendRedirect(redirectURL);
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }

    // ...
}
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Your inputs for [this question](http://stackoverflow.com/questions/11373665/how-to-get-bean-data-in-jsp), please – Fahim Parkar Jul 07 '12 at 09:13
  • How do i access the values fromManaged Beans from Faces Context to determine the redirect url in servlet filter ? – user684434 Jul 10 '12 at 18:57
  • The `FacesContext` isn't available in a filter at all. Just grab them the low level Servlet API way as attribute from the desired scope. See also http://stackoverflow.com/questions/2633112/jsf-get-managed-bean-by-name/2633733#2633733 So, a session scoped JSF managed bean would be available by `SessionBean sessionBean = (SessionBean) request.getSession().getAttribute("sessionBean");`. – BalusC Jul 10 '12 at 19:05
  • Thanks Balusc..I will try that ... If i have servlet 2.x ,can i use this – user684434 Jul 10 '12 at 19:13
  • Why not? JSF runs on top of Servlet API. Without Servlet API, JSF won't even work. – BalusC Jul 10 '12 at 19:15