*
The moose likes Beginning Java and the fly likes How do I use my functioning Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I use my functioning Java?" Watch "How do I use my functioning Java?" New topic
Author

How do I use my functioning Java?

B. Dugas
Greenhorn

Joined: May 14, 2011
Posts: 3
I'm very new to Java, so please excuse my obvious ignorance. I'm trying to make a silent login work to a particular website. The company has given me sample Java code, and the encryption key. I hard coded the encryption key into the code, along with my username, for testing. I compiled the code with javac from the command line. When I run the Java class from the command line, it outputs a long url string. If I copy that to my browser address bar, it works. What I need help with, is placing a link somewhere on a web page that will call this Java class and make it work. The code finishes out with a "System.out.println" and that works from a command line. But I can't make sense of this. Any help or assistance would be greatly appreciated. Below is the .java code that works.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Welcome to the Ranch

What happens is you set up a user name "jdoe" number "1234", etc. (line 13-25) and Strings with the date in eg "2011-05-14T12:34:56GMT" or something similar (line 26-35).
Then it seems to divide the whole lot into an array of bytes, changes each byte into hexadecimal format, joins them all up with a StringBuilder (line 40-64), and uses that information to make a log in (line 69 to 76). Note the information put into the StringBuilder appears to have been changed into its SHA256 form. That is not true encryption, because you can turn a String into an SHA256 but you can't turn the SHA256 back into the String.

I don't think it actually logs on, but it displays what the URL would be if you did log on. At the next stage in development, I presume you would use that URL in real life.

If you require more details, please ask again.

B. Dugas
Greenhorn

Joined: May 14, 2011
Posts: 3
Thanks Campbell!
Because I’m really a fish out of water, I didn’t explain myself all that well. You are correct, I am looking to use the URL in real life. The output from the code generates a URL when I run it using javac.exe from the command line. However, I need to be able to use this on a web page. I imagine I’m going to “call” (if that’s even the right terminology) this Java class, and send it the user name. After calling this class, it should return a URL that should log the user right in to this website.

So, up to now, I’ve compiled the code to a .class file and verified the code works using javac.exe at the command prompt. How do I implement this on my website? Can an html page call/use this .class file to generate the URL like I need? Please let me know if I need to clarify any more details. Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Sounds like what you need to do is to create a web application that contains a servlet that calls your class to generate the URL. You can then forward to a JSP page that will generate an HTML file, passing the UTL as a scoped variable. In the JSP you can create a link that the user can click up to visit the URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
B. Dugas
Greenhorn

Joined: May 14, 2011
Posts: 3
Wow, sounds like I may be in over my head on this one. The web page I have access to post my hyperlink is an internal server running Front Page extensions (inside our work domain). I'm not sure it will support JSP pages and servlets. I was hoping I could somehow let an HTML page make use of this Java class I have on my hands. I would have no problem going dig and learning the processes to make your suggestions work, however if this requires me to start manipulating the web server or changing/installing things, then our IT department will shoot this whole thing down.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do I use my functioning Java?