This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes HTTP Vs HTTPS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Vs HTTPS" Watch "HTTP Vs HTTPS" New topic
Author

HTTP Vs HTTPS

Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
Hi,
I have a servlet that hits a JSP using the java.net.URL class. The URL is constructed during runtime. The code works fine with HTTP. But, with HTTPS, I get a MalformedURLException, with the message that HTTPS is unknown protocol. Is this because the URL class can only handle HTTP requests? If yes, is there a way around this problem? Any help would be appreicated.
-Akram
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
hi,
I�m having a problem very simmilar with this, if you sort it out please let me know, and if I do be sure that I�ll post here
bye.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

Do you mean servlet or applet? An applet might not be allowed to open an HTTPS connection unless it had been loaded from an HTTPS server.


Customer surveys are for companies who didn't pay proper attention to begin with.
Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
Tim,
I do mean a servlet.
Marcos,
one solution to this is to use RequestDispatcher.include(). The only problem with this is that you will be including the output from the JSP. My JSPs basically do NOT print any thing on to the screen, so I am okay with it, except that when there is an error in the JSP, the compilation errors are thrown on to the screen and I am looking for a way around it. Let me know if this helped/ if you know a solution. Thanks.
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
What you need is to download and install (have in classpaths) the JSSE package from sun.com
Then you have to set some security parameters (it will be clear once you see the examples that come with it) and you should be able to use HTTPS without any problems.
Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
Mak,
I do not think that would solve my problem. HTTPS seems to be working fine in serving my other JSPs and HTML pages. So, I don't think that any thing is wrong with the way HTTPS is set up. Moreover, the servlet works fine if I use RequestDispatcher.include(). Thanks.
-Akram
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Mak was correct in saying that you need to use Java Secure Socket Extension (JSSE) (check out http://java.sun.com/products/jsse/)
The standard java.net.* classes do not know how to handle SSL connections and that is why you are getting a MalformedURLException.
Once you have the JSSE classes in your classpath you can then access new classes such as HttpsURLConnection which can then connect to a HTTPS resource.
Other security properties are required to be set also, which are mentioned at Sun's website.
James.

[This message has been edited by james swan (edited July 25, 2001).]
[This message has been edited by james swan (edited July 25, 2001).]
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Here is a simple example you can run from cmd line once you have downloaded JSSE classes from Sun (provided you are not behind a fire wall/proxy server configuration.

When you run this you should see the HTML that Yahoo sends when connecting to YahooMail via secure connection.
James.
[This message has been edited by james swan (edited July 25, 2001).]
Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
James,
I didn't realize that I was taking the wrong approach until you pointed it out. Thanks for all your help.
-Akram
Dave Van Even
Ranch Hand

Joined: Jul 19, 2001
Posts: 101
Originally posted by Akram Reja:
Hi,
I have a servlet that hits a JSP using the java.net.URL class. The URL is constructed during runtime. The code works fine with HTTP. But, with HTTPS, I get a MalformedURLException, with the message that HTTPS is unknown protocol. Is this because the URL class can only handle HTTP requests? If yes, is there a way around this problem? Any help would be appreicated.
-Akram

Hi, Akram Reja
could you send me that code ? I've been trying to make a servlet that does a request on a JSP or HTML, compresses the response with gzip and return that to the client...
I figured that with the right mapping patern, that can be very easy to return compressed JSP's to the client...
only problem is that it doesn't work with JSP's !!! I don't know how comes..
my email is: davevaneven@hotmail.com (don't have to send everything, just the main code if possible)
THANKS!!! (hope you read this )
Dave Van Even

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Vs HTTPS
 
Similar Threads
SSL with Jbuilder ?
How to connect to HTTPS url using java URL Class
Different Between Http and Https protocols
Using SSL on HttpURLConnection
SSL