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?
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.
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.
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.
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/"/>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With