Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto direct to "my web application" from "root (/)" context in JBoss?

I am using JBoss 6.0 .

I have deployed my web application: myApp.ear under the web-context: "/test". So in browser-url if I type "http://localhost:8080/test/", I do get my login page (myLogin.jsp).

Since my WAR exists inside a EAR file, I have specified the context root in the application.xml file using a context-root element inside of the web module - i.e.

<module>
    <web>
        <web-uri>myWeb.war</web-uri>
        <context-root>/test</context-root>
    </web>
</module>

My question is how to auto direct user to my web-app from "root context"?

I mean if user types "http://localhost:8080/", I would expect my web-application's login page to load (instead of JBoss's default ROOT.war's index.html page).

I deleted existing index.html from {JBOSS}\server\default\deploy\ROOT.war and created a login.jsp there. Now I can see that "login.jsp" is getting invoked when I type http://localhost:8080/. But I can not redirect user-request to my web-app's login page.

In that login.jsp, I have tried with: <jsp:forward page="/test" />, but I get error: "HTTP Status 404 - /test".

If I invoke like <jsp:forward page="/test/myLogin.jsp" /> I still get the same 404 error.

Can any one suggest how to achieve the auto-direct to my web-app from root-context?

like image 610
javauser71 Avatar asked Apr 18 '11 21:04

javauser71


People also ask

How do you find the context root of a web application?

The context root for an application is determined by how it is deployed. When a web application is deployed inside an EAR file, the context root is specified in the application. xml file of the EAR, using a context-root element inside of a web module.

How do you set root context?

1.1 Right click on the project, select Properties , Web Project Settings , update the context root here. 1.2 Remove your web app from the server and add it back. The context root should be updated. 1.3 If step 2 is failing, delete the server, create a new server and add back the web app.

What is context root in URL?

The context root is part of the URL you use to connect to the application. A URL reference to an IBM® SPSS® Collaboration and Deployment Services application includes the following elements: URL prefix. Consists of the protocol, the server name or IP address, and the port number.


2 Answers

You need to keep index.html in default deploy folder and forward request to your web module.

For example keep following line only in index.html

<META HTTP-EQUIV="Refresh" CONTENT="0; URL=/test/"/> 
like image 166
Senthil Avatar answered Sep 27 '22 18:09

Senthil


The answer from Senthil works nice, but user could see the actual redirect done by the browser (page blinks). The redirect can be done also with rewrite [1, 2] functionality of the JBoss server, which supports HTTP Redirect with 30x codes (no blink).

You can either add the rewrite to your app directly (web.xml, jboss-web.xml) and specify the redirect rules in rewrite.properties - not shown here.

Or you can modify the server configuration on it's own without touching the original application. I find this solution handy because the application is left intact.

Use case: We use this for EJBCA deployment (not our app), it sets it's context root to /ejbca. We want to preserve the default deployment process provided by the packaged ant script while in the same time we would like to add a redirect from / to /ejbca as some kind of default, for user friendliness. If user wants to change it, it's done simply by modifying standalone.xml without need to redeploy the whole app.

Edit standalone.xml:

<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
    <virtual-server name="default-host" enable-welcome-root="true">
        <alias name="localhost"/>
        <rewrite pattern="^/$" substitution="/test" flags="L,QSA,R" />
    </virtual-server>
</subsystem>
like image 20
ph4r05 Avatar answered Sep 27 '22 18:09

ph4r05