Redirect from HTTP to HTTPS on Glassfish

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

Build

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

Instructions
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.

<web-app>

<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>Anything</web-resource-name>
<description>This will make the constraint affect all pages of the application</description>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

</web-app>

References