1 Reply Latest reply on Dec 12, 2006 6:41 AM by Pete Muir

    ServletRequest in Seam

    Gregory Nikle Apprentice

      Can anyone tell me how to get full path of my servlet qestuest?

      In struts I have filter like this:

      public void doFilter(ServletRequest servletRequest,
       ServletResponse servletResponse,
       FilterChain chain) throws IOException, ServletException {
       //------------------------------------------
      HttpServletRequest req = (HttpServletRequest) servletRequest;
      HttpServletResponse res = (HttpServletResponse) servletResponse;
      String a = req.getRequestURI();
      StringBuffer b = req.getRequestURL();
      


      and getRequestUri gives me full path to request but in Seam i get somethink like this:
      http://localhost:8080/myApp/
      so where's the other stuff?

      how can I get other?
      I need to get to full request:
      http://localhost:8080/myApp/index.seam
      or when I write some virtual address who doesn't exist like
      http://localhost:8080/myApp/how.old.is.Gavin.King.com
      i need to get also those request, but how?

      String c = req.getServletPath(); gives me only filename of the request like
      index.xhtml
      Can anyone help me?

        • 1. Re: ServletRequest in Seam
          Pete Muir Master

          I use this in a phase listener:

          protected String getExternalApplicationRoot(FacesContext ctx) {
           if (ctx.getExternalContext().getRequest() instanceof HttpServletRequest) {
           HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest();
           return "http://" + request.getServerName() + ":" + request.getServerPort() + ctx.getExternalContext().getRequestContextPath() + "/";
           } else {
           return null;
           }
          }


          If the user was viewing http://foo.bar.com:1234/myApp/management/editUser.jsf the String returned from the function would be http://foo.bar.com:1234/myApp. Does that help?