Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Applet not communicating with Servlet, Help Required. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Applet not communicating with Servlet, Help Required." Watch "Applet not communicating with Servlet, Help Required." New topic
Author

Applet not communicating with Servlet, Help Required.

Declan Conlon
Ranch Hand

Joined: Jul 03, 2001
Posts: 34
I'm not sure what is wrong with my applet. Originally I had an applet that accessed a file and outputted it to a servlet. I then wanted to add a progress bar but the file access and transfer process were to intensive to make the progress workable. I moved the progress bar to a thread and the file access and transfer also. Now the progress bar works but there seems to be a problem with connecting to the servlet. A case of fix one thing brake another. Has anyone any ideas as to why this may be the case. The code is the same as I just pass datainputstream and a dataoutputstream to the thread and reuse the same codefrom there. The file inputs correctly and I have tried the older version of the code and it still works. Thanks for any help and ideas you can give.
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
hi,
well if it run before and now doesnt, then there must be a change.
can you post part of the code ?
karl
Declan Conlon
Ranch Hand

Joined: Jul 03, 2001
Posts: 34
Here's the code
+++++++++++++++NEW CODE++++++++++++++++++
public void postData() throws IOException, FileNotFoundException
{
File outfile = new File(globalfilestr);
URL location = new URL(getCodeBase(), "<URL GOES HERE>");
URLConnection out = location.openConnection();
out.setUseCaches(false);
out.setRequestProperty("Content-Type", "application/x-java-serialized-object");
out.setRequestProperty("Filename", globalfilename);
FileInputStream filein = new FileInputStream(outfile);
DataInputStream datain = new DataInputStream(filein);
DataOutputStream dataout = new DataOutputStream(out.getOutputStream());
filethread = new FileBG();
//Setting thread variables
filethread.setFileSize(outfile.length());
filethread.setInputStream(datain);
filethread.setOutputStream(dataout);
filethread.setPgBar(pgbar);
filethread.start();
}
//PLUS THREAD CODE
float quantumfloat = filesize/100.0f;
int quantum = (int)quantumfloat;
long byteswritten = 0;
float percentup = 0;
barthread = new BarBG();
barthread.pgbar = pgbar;
barthread.start();
while (true)
{
byte readbyte = datain.readByte();
dataout.writeByte(readbyte);
byteswritten++;
if((byteswritten % quantum) == 0 | | (byteswritten % filesize) == 0)
{
float raw = (byteswritten/(float)filesize);
percentup = (raw * 100);
System.out.println(readbyte);
barthread.setPercent(raw);
}
}
+++++++++++++++++OLD CODE++++++++++++++++
private void postData() throws IOException
{
File outfile = new File(globalfilestr);
URL location = new URL(getCodeBase(), "<URL GOES HERE>");
URLConnection out = location.openConnection();
out.setUseCaches(false);
out.setRequestProperty("Content-Type", "application/x-java-serialized-object");
out.setRequestProperty("Filename", globalfilename);
msgarea.append("Filename encoded: " + globalfilename + "\n");
FileInputStream filein = new FileInputStream(outfile);
DataInputStream datain = new DataInputStream(filein);
DataOutputStream dataout = new DataOutputStream(out.getOutputStream());
With same code as thread above for reading and writing the data.
Is there some scoping problem with the DataOutputStream reference? As you see I am essentially doing the same thing in both cases. Hope you can shed some light on the matter.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Applet not communicating with Servlet, Help Required.
 
Similar Threads
Transfer control from Third party Applet.
data loss during file transfer from applet2servlet
I can't get my progress dialog to update
file upload using HTTP & the Transport layer
Thread not opening connections properly.