Hi Matt

Here is the code I have written to redirect connection from HTTP to HTTPS
and vice versa

    /*
    *
    *
    * Function to perform HTTP and HTTPS redirection
    * Author : Michael Mok ([EMAIL PROTECTED])
    * Version : 1.0
    *
    *
    */

    public static String getURL(org.apache.struts.action.ActionForward
forward, javax.servlet.http.HttpServletRequest                                  
request, boolean secure)
{
        String path = forward.getPath();
        String contextPath =
request.getContextPath().equals("/")?"":request.getContextPath();
        String serverPort = Integer.toString(request.getServerPort());
        StringBuffer url = new StringBuffer();
        if (secure) { //user has requested to secure the server
            url.append("https://";);
            serverPort = ( serverPort.equals("80")?"":":"+serverPort);
        } else {
            url.append("http://";);
            serverPort = ( serverPort.equals("443")?"":":"+serverPort);
        }
        url.append(request.getServerName());
        //this only work if you are using the default port 80 and port 443
as secure connection
        url.append(serverPort);
        url.append(request.getContextPath());
        url.append(path);
        return url.toString();
    }

-----Original Message-----
From: Matt Raible [mailto:[EMAIL PROTECTED]]
Sent: Friday, 5 October 2001 4:48
To: [EMAIL PROTECTED]
Subject: https and struts - forcing an https connection


Does anyone know if it's possible in xml configuration files (or my jsp
using
tag libraries) to make my application only accessible via an https
connection?

I know I can use javascript on my form-login page to do a redirection, but
I'm
hoping there's a cleaner way.

Thanks,

Matt


__________________________________________________
Do You Yahoo!?
NEW from Yahoo! GeoCities - quick and easy web site hosting, just
$8.95/month.
http://geocities.yahoo.com/ps/info1

Reply via email to