Redirect from HTTP to HTTPS on Glassfish

This tutorial is intended to show you how you can force various url patterns to use HTTPS if a user tries to use HTTP.


  • Glassfish 4.1
  • Netbeans 8.1 (Not necessary, will have instruction for both)
  • JavaEE 7 (Don’t think its necessary)

Navigate to your Web Application Archive’s (WAR’s) web.xml file.

Method 1: Netbeans

NB Step 1

NB Step 2

Method 2: Good ol’ Copy n’ Paste

The above steps would have created the following code which you would add into your file. I apologize it would not save the spaces.


<description>This will make the constraint affect all pages of the application</description>



Set context-root of Application running on Glassfish as the Domain Base


Whether you want to set your ear, war or whatever type of application up on Glassfish, we typically want to get rid of the default landing page and replace it with one of the apps. This guide will show you how, with one image. This method is the easiest but has a caveat which I will mention later. It should work in Glassfish 3 and beyond, at the least.


  • Glassfish 4.1
  • Using an Enterprise Application Archive (EAR)


  • Name of configuration and virtual server are default


  1. Deploy your application
  2. Navigate to Configurations > server-config > Virtual Servers > server
  3. Select desired application on Default Web Module
  4. Save

Instruction Image

If you specified in the configurations of your file a different context root (file depends on what type of application) then you will be able to access the application from the Domain Base as well as the context root defined in the application’s configuration file.