URL Redirection in Sun Java System Application Server
This article uses examples to show how to configure web application
URLs in
Sun Java System Application Server or GlassFish. This article assumes
you are using
Application Server 9.0, Application Server 9.1, GlassFish v1, or
GlassFish v2.
The Context Root of a WAR File
The context root of a web application archive (WAR) file that is
not deployed within an enterprise application archive (EAR) is defined
in the <WARprojectname>/web/WEB-INF/sun-web.xml
file.
In this sample context root definition in the sun-web.xml
file, /mywarname is
the context root:
The context root of a web application archive (WAR) file that is
deployed within an enterprise application archive (EAR) is defined in
the <EARprojectname>/conf/application.xml
file
Changing the Welcome File of a Web Application
To change the welcome file of your web application, add the required
filename
to the welcome-file-list in the web.xml file corresponding to your web
application.
For example, you have created a sample web application that opens index.jsp
when you launch the web application. If you want to open mywelcomefile.jsp
instead, add the following lines to the web.xml
file.
You can use the Default Web Module option in the Virtual Server
configuration to hide the WAR name (I other words, the context root)
from
the URL used for accessing your web pages. The following procedure
enables your
website users to type in http://www.mywebsite.com
and be redirected or forwarded to http://www.mywebsite.com/hello.
Log in to the Admin Console of Sun Java System Application
Server or GlassFish.
In the Admin Console, expand the Configurations node.
Expand the server-config node.
Ignore this step if you are running a developer domain (a domain
that does not have clustering capability).
Expand HTTP Service.
Expand Virtual Servers.
Click server.
On the Edit Virtual Server page, select the hello
as the Default Web Module.
Specifying the default WAR in the virtual server configuration
eliminates the need to
enter the war name in the URL.
URL Redirection Within a Domain
You can use the url-prefix element of
the redirect_ property to forward
a URL to another URL in the same domain.
The following procedure shows how to enable visitors to a web site
to type in http://www.mywebsite.com/myproduct1
and be redirected or forwarded to http://www.mywebsite.com/mywarname/products/myproduct1.jsp.
Log in to the Admin Console of Sun Java System Application
Server or GlassFish.
In the Admin Console, expand the Configurations node.
Expand the server-config node.
Ignore this step if you are running a developer domain (a domain
that does not have clustering capability).
Expand HTTP Service.
Expand Virtual Servers.
Click server.
On the Edit Virtual Server page, click the Add Property button.
In the Name column, type redirect_1.
If you are using Application Server 9.0, type from=/<context-root>/myproduct1url-prefix=/mywarname/mypages/products/myproduct1.jsp
in the Value column.
Note - The value of the <context-root>
you provide here needs to match the value of the context root specified
in the web.xml or application.xml
file.
If you are using Application Server 9.1, type from=/myproduct1url-prefix=/mywarname/mypages/products/myproduct1.jsp
in the Value column.
URL Redirection to Another Domain
You can use the url element of the redirect_ property to forward a
URL to another URL in the same domain.
The following procedure shows how to enable visitors to a web site
to type in http://www.mywebsite.com/myproduct1
and be redirected or forwarded to http://java.sun.com.
Log in to the Admin Console of Sun Java System Application
Server or GlassFish.
In the Admin Console, expand the Configurations node.
Expand the server-config node.
Ignore this step if you are running a developer domain (a domain
that does not have clustering capability).
Expand HTTP Service.
Expand Virtual Servers.
Click server.
On the Edit Virtual Server page, click the Add Property button.
In the Name column, type redirect_1.
If you are using Application Server 9.0, type from=/<context-root>/myproduct1url=http://java.sun.com
in the Value column.
Note - The value of the <context-root>
you provide here needs to match the value of the context root specified
in the web.xml or application.xml
file.
If you are using Application Server 9.1, type from=/myproduct1url=http://java.sun.com in the Value column.
Comments (latest comments first)
Discuss and comment on this resource in the BigAdmin Wiki
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License.