1 2 3 Previous Next 31 Replies Latest reply on Oct 11, 2012 11:04 PM by ohmygod Go to original post
      • 15. Re: AS7 and context-root
        richardrobinson

        One reason to need an index.jsp page at the context root which redirects is if you have multiple webapps, each with a diff. domain name. You want to publish the URL as www.example.com and www.example2.com -- and have the index.jsp at ROOT context switch to the right webapp based on domain name.

         

        The links in the web app may be hard coded to the webapp name (not a best practice, admittedly) so it's not so simple as merely changing the context root; one would also have to go through every link in the web app and make them point to context root instead.

         

        Is there any way to configure a DirectoryIndex of sorts (such as in Apache httpd). index.jsp works in the welcome-content-root, but it's not apparely configurable as a index file. (A work around is to make the index.html redirect to the index.jsp, which then redirects to the right webapp based on domain name), but that's yet anohter round trip to client.

         

        # # #

         

        The workaround for this is not bad -- disable the welcome-context-root and create an anemic ROOT.war that includes an index.jsp in it. The index.jsp has the logic to redirect to the right webapp based on context or domain name of incoming URL.

        • 16. Re: AS7 and context-root
          jaikiran

          Richard Robinson wrote:

           

           

          # # #

           

          The workaround for this is not bad -- disable the welcome-context-root and create an anemic ROOT.war that includes an index.jsp in it. The index.jsp has the logic to redirect to the right webapp based on context or domain name of incoming URL.

          That's not a "workaround", that in fact is the right way to do this. The welcome-content application was meant just to provide the welcome content when you access the page on a fresh install of AS7. It was not meant to do anything else and the expectation is that if your servers needs an application at root context, then the welcome-content has to be disabled and an application deployed to the / context. What that application does is then entirely upto the users.

          • 17. Re: AS7 and context-root
            ohmygod

            Hi Richard,

             

            Have you tried this successfully? I have put a ROOT.war including an index.jsp in it under standalone\deployments or the same directory as welcome-content folder but neither is working.

             

            Can you explain a little more clearly how to make this work? Thanks a lot.

            • 18. Re: AS7 and context-root
              richardrobinson

              Hi Mike,

               

              Yes, I have it working and running in production. Essentially, here's what I did.

               

              • Disabled the welcome-content folder.
              • Then deployed a ROOT.war, which has merely one index.jsp, the content of which is below. I don't think I had to do anything else.

               

               

              I had to do it this way because I have multiple domain names but just one IP address, AND I didn't want to remap all my links in one of the apps.

               

               

               

               

               

               

               

               

               

              {code}

              <%

               

              String url = request.getRequestURL().toString();

               

              if ( url.contains("example"

              ) ) {

              response.sendRedirect(

              "http://www.example.org/ex/index.dhtml"

              );

              }

              else if ( url.contains("example2") || url.contains( "/ex2/"

              ) ) {

              response.sendRedirect(

              "http://www.example.org/ex2/index.dhtml"

              );

              }

              else if ( url.contains("example3") || url.contains( "/ex3/"

              ) ) {

              response.sendRedirect(

              "http://www.example3.org/ex3/index.dhtml"

              );

              }

              else

              {

              %>

               

              Yakity yak, don't talk back

              {code}

                    // nothing fall back to html below

              }

               

              • 19. Re: AS7 and context-root
                ohmygod

                Hi Richard,

                 

                What location did you put the ROOT.war at?

                • 20. Re: AS7 and context-root
                  richardrobinson

                  standalone/deployments

                  • 21. Re: AS7 and context-root
                    ohmygod

                    Yes, I have put it there but the url is not accessible at all "http://localhost:port". My content of index.jsp is just one line:

                    <% response.sendRedirect("/demo/"); %>

                     

                    // demo is the context of my real application. I used this line to try to make it redirect to my real application.

                     

                    Anything I did wrong?

                    • 22. Re: AS7 and context-root
                      richardrobinson

                      What's your public interface configured like?

                       

                      Two possible configurations that would work (if you're accessing it from same box).

                       

                      {code}

                       

                              <interface name="public">
                                  <inet-address value="${jboss.bind.address:127.0.0.1}"/>

                       

                      or

                       

                              <interface name="public">
                                  <inet-address value="${jboss.bind.address:0.0.0.0}"/>

                      {code}

                      • 23. Re: AS7 and context-root
                        richardrobinson

                        Presumably http://localhost:port/demo works though if you hit it directly?

                        • 24. Re: AS7 and context-root
                          ohmygod

                          It is this one

                          <interface name="public">

                                      <inet-address value="${jboss.bind.address:127.0.0.1}"/>

                          </interface>

                           

                          And yes, the link with demo context is working fine.

                          • 25. Re: AS7 and context-root
                            richardrobinson

                            Change to response.sendRedirect("http://localhost:port/demo") -- not relative URI or merely context as it has to go back to the client -- and that should do the trick. However, if it's really "localhost" it *may* but definitely won't work on a separate host.

                            • 26. Re: AS7 and context-root
                              ohmygod

                              Correct, that is a problem. Do you think there is a way to resolve this?

                              • 27. Re: AS7 and context-root
                                richardrobinson

                                If you're just accessing it one the one host, it should work w/ localhost.

                                 

                                If you're accessing it on another host on the network, you could use the IP address or a local domain name (etc/hosts)

                                 

                                Or if you're accessing it from outside the network (e.g. internet), you'll need a public domain name.

                                • 28. Re: AS7 and context-root
                                  ohmygod

                                  I just tried with <% response.sendRedirect("http://localhost:port/demo"); %> but it is still not accessbile by http://localhost:port.

                                   

                                  Anything I missed?

                                  • 29. Re: AS7 and context-root
                                    ohmygod

                                    Hi Richard, I want to confirm with you about the standalone configuration xml. Besides the enable-welcome-root="false" setting, is there anything that needs to be changed to make this work?

                                     

                                    Or can you attach your standalone.xml for me?