🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #639

Re: Java to ASP communication

#639
From: Patrik Lundin
Date: Thu, 15 Apr 1999 00:00
82 lines
2453 bytes

> I need to pass several strings from a Java applet to a ASP (active server
> page) page. How is this done?

Th easiest way is just to send it in the url and get it in the ASP page
with Request.QueryString( "name" ) or just Request( "name" )

Example :

In the Applet :
--------------------------------

public void
someMethod()
{
  Url url;

  try{
     url = new URL( "http://sameserver.as.applet/script.asp?value=" + URLEncoder.encode( somevariable ) );
  }catch( Exception ex ){}

}

Where somevariable is the stuff you want to send.

In the ASP script:
--------------------------------

<%

stuff = Request.QueryString( "value" )

%>
This was the stuff: <%= stuff %>



If you want to get some reply from the script, just read from the url :


public void
someMethod()
{
  Url url;
  String str;

  try{
     url = new URL( "http://sameserver.as.applet/script.asp?value=" + URLEncoder.encode( somevariable ) );
     str = readURL( url );
  }catch( Exception ex ){}

}

String
readURL( URL filepath ) throws java.lang.Exception
{
  DataInputStream is = null;
  StringBuffer filecontents = null;
  String line = "";

  filecontents = new StringBuffer( 1024 );

  is = new DataInputStream( new BufferedInputStream( filepath.openStream() ) );

  while( true )
  {
    line = is.readLine();
    if( line == null ) break;
    filecontents.append( line ).append( "\n" );
  }

  is.close();

  return filecontents.toString();
}


--------------------------
Patrik Lundin
http://www.javathings.com
--------------------------
Technical Details
Message-ID: <37151968.6836E71A@mbox301.swipnet.se>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.117f1da1c1481082989680@news.tele.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9a23,dd6cf6488210777f
X-Google-Attributes: gidf9a23,public
X-Google-Thread: 10a146,dd6cf6488210777f
X-Google-Attributes: gid10a146,public
From: Patrik Lundin <patrik.lundin@mbox301.swipnet.se>
Subject: Re: Java to ASP communication
Date: 1999/04/15
Message-ID: <37151968.6836E71A@mbox301.swipnet.se>
X-Deja-AN: 466480902
Content-Transfer-Encoding: 7bit
References: <MPG.117f1da1c1481082989680@news.tele.dk>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news-abuse@swip.net
X-Trace: nntpserver.swip.net 924129562 130.244.111.181 (Thu, 15 Apr 1999 00:39:22 MET DST)
Organization: A Customer of Tele2
MIME-Version: 1.0
NNTP-Posting-Date: Thu, 15 Apr 1999 00:39:22 MET DST
Newsgroups: comp.lang.java.programmer,dk.edb.programmering.java