[thelist] Jumping into Java

Warden, Matt mwarden at odyssey-design.com
Sun Jan 21 01:15:31 CST 2001


> Matt, my hero.  :)
>
> Actually, I want to do the same thing that you just did with my slots
> game.  ie....send userid and points to page that hits the db.
>
> Can you tell me the function I should be looking at for this?

LOL! You haven't been around Java very much, have you ;-)

Java isn't very PHP-like. To do what you want to do, (my Java is a tad rusty,
so someone correct me if I'm wrong) you are going to want to look into the
URLConnection object. And, it's not going to be as easy as passing a URL,
*especially* if you need the data to be POSTed for security/size reasons.

I guess the other option you have is to create a socket. This would be a model
of an HTTP request in Java (code untested, unoptimized, FYI only):

String msg="GET /myfile.htm HTTP/1.1\r\n";
msg = msg + "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword,
application/x-comet, */*\n";
msg = msg + "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)\r\n";

Then you would open the socket and write the request:

Socket socket = new Socket("www.mydomain.com", 80);
socket.getOutputStream().write(msg.getBytes());

Then, if you want to read the response (for error messages, confirmation,
etc.):

PrintWriter outpage = response.getWriter();

InputStreamReader isr = new InputStreamReader(socket.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine;
while ((inputLine = in.readLine()) != null)
{
 outpage.println(inputLine);
}
outpage.println("Hi");
in.close();
outpage.close();
socket.close();


Assuming that request and response are HttpRequest and HttpResponse objects,
respectively.

That's roughly what you would have to do for this method. But, just like in
PHP, there is usually more than one way to do things (I've given you two, and
I'm sure there are more).

Check out the javadocs at java.sun.com for more information on URLConnection.


--
mattwarden
mattwarden.com


> Also, these programs appear to be a little old.  When I compiled one of
> them I got several warnings about some functions being
> depreciated.    Since this is my first attempt at a compiled language,
> should I be concerned?
>
> Chris
>
> At 09:02 PM 1/20/01, you wrote:
> >If you are talking about what I think you are talking about, yes. BUT, it
> >depends on what you are using to load the webpage. If you are displaying
the
> >webpage and use certain Java objects (like the one to emulate a IE frame),
you
> >most likely have all the options to the user that you would have if it was
a
> >regular browser window. Other objects will not give these options or let
you
> >turn them off. If you are simply calling a webpage, then absolutely. The
> >filename will be hidden in the compiled source.
> >
> >
> >--
> >mattwarden
> >mattwarden.com
> >
> >
> >----- Original Message -----
> >From: CDitty <mail at redhotsweeps.com>
> >To: <thelist at lists.evolt.org>
> >Sent: Saturday, January 20, 2001 4:58 PM
> >Subject: [thelist] Jumping into Java
> >
> >
> > > Hello all,
> > >
> > > I have found a website that will allow people to download their Java
games
> > > and use on our site.  My question is, is it possible to have Java access
a
> > > webpage and it not be known to the user?  ie....In Flash I can use the
> > > LoadVariables function.  Is there anything similar in Java?
> > >
> > > Thanks
> > >
> > > CDitty
> > >
> > >
> > > ---------------------------------------
> > > For unsubscribe and other options, including
> > > the Tip Harvester and archive of TheList go to:
> > > http://lists.evolt.org Workers of the Web, evolt !
> > >
> >
> >
> >---------------------------------------
> >For unsubscribe and other options, including
> >the Tip Harvester and archive of TheList go to:
> >http://lists.evolt.org Workers of the Web, evolt !
>
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !
>





More information about the thelist mailing list