p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Java Applet calling an ASP problem


Message #1 by "Greg Griffiths" <gregory_griffiths@c...> on Wed, 23 Aug 2000 14:55:20
you have the url defined:

       String paramSubmitURL="http://127.0.0.1/scripts/npdwriter.asp";

now from my memory, it would seem that unless this applet was signed you are
experiencing a "security error"

if this is true, just make the url a local one:

       String paramSubmitURL="scripts/npdwriter.asp";

i believe the applet can only read from the source server without being
required to be a signed one.




-----Original Message-----
From: Greg Griffiths 
Sent: Wednesday, August 23, 2000 3:12 PM
To: Code Clinic
Subject: [proasp_codeclinic] Java Applet calling an ASP problem


I am using this ASP to get the info from the applet and then write a file

 <%
 Dim tasknames
 
 ' get the input
 tasknames=Request.Form("tasknames")
 
 ' display it
 Response.Write(tasknames)
 
 ' save to a file
 Dim fso, tf
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set tf = fso.CreateTextFile("c:\testfile.txt", True)
 ' Write a line with a newline character.
 tf.WriteLine("Testing 1, 2, 3.")
 ' Write three newline characters to the file.
 tf.WriteBlankLines(3)
 ' Write a line.
 tf.Write (tasknames&" HOLA")
 tf.Close
 
 Response.Write("done")
 %>
 
 where TASKNAMES is a string being sent from the Applet, but  for some 
reason I get the file, but the value of Tasknames is blank, any  ideas why 
? The save routine of the applet is as follows :-
 
 private void save()
     {
       URL url;
       URLConnection connection;
       HttpURLConnection httpconnection;
       InputStream intstr;
       OutputStream outstr;
       OutputStreamWriter outstrw;
 
       String temptaskid = "";
       String temptasknames = "";
       String tempstartdates = "";
       String tempfinishdates = "";
       String tempsubwfid = "";
       String tempwfid = "";
       String countstr = "";
       String paramSubmitURL="http://127.0.0.1/scripts/npdwriter.asp";
 
       System.err.println("SAVING");
 
       try
       {
         url = new URL(paramSubmitURL);
         connection = url.openConnection();
         httpconnection = (HttpURLConnection) connection;
 
         httpconnection.setRequestMethod("POST");
         httpconnection.setDoOutput(true);
         outstr = httpconnection.getOutputStream();
         outstrw = new OutputStreamWriter(outstr);
 
         // Output the Task Names
         temptasknames = "tasknames=" + taskNames[0];
         for(int i = 1; i < count; i++)
         {
           temptasknames = "," + taskNames[i];
         }
         outstrw.write(temptasknames + "\n", 0, temptasknames.length());
 
 
         // Output the Task IDs
         temptaskid = "taskid=" + taskID[0];
         for(int i = 1; i < count; i++)
           temptaskid = "," + taskID[i];
	   outstrw.write(temptaskid + "\n", 0, temptaskid.length());
	 
 
         // Output the Sub WF IDs
         tempsubwfid = "subwfid=" + subWfID[0];
         for(int i = 1; i < count; i++)
           tempsubwfid = "," + subWfID[i];
         outstrw.write(tempsubwfid + "\n", 0, tempsubwfid.length());
 
 
         // Output the wf id
         tempwfid = "wfid=" + wfID;
         outstrw.write(tempwfid + "\n", 0, tempwfid.length());
 
 
         // Output the start dates
         tempstartdates = "start=" + datef.format(start[0].getTime());
         for(int i = 1; i < count; i++)
           tempstartdates = "," + datef.format(start[i].getTime());
         outstrw.write(tempstartdates + "\n", 0, tempstartdates.length());
 
 
         // Output the finish dates
         tempfinishdates = "finish=" +  datef.format(finish[0].getTime());
         for(int i = 1; i < count; i++)
           tempfinishdates = "," + datef.format(finish[i].getTime());
         outstrw.write(tempfinishdates + "\n", 0,  
tempfinishdates.length());
 
         // Output the count
         countstr = "count=" + count;
         outstrw.write(countstr, 0, countstr.length());
 
 
         // Read the status returned by the page
         intstr = httpconnection.getInputStream();
         int x = 0;
         x = intstr.read();
         if (x == 'o' || x == 'O')
           saved = true;
       }
       catch (Exception e)
       {
         System.err.println("An error occured whilst connecting and/or 
sending data to the URL connection.\nURL: " + paramSubmitURL);
       }
     }


  Return to Index