473,761 Members | 4,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java applet

Hy!

My next problem is to make an applet from my program. I have just add the
"extend applet" to my class and removed the main-method by the start-method
of the applet.
I was thinking that this is enough, but it does not work, the file does not
appear on the server. I have tried to start the applet local and also from
the server, but it does not work.
Here is the code:
*************** *************** ***********
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.net.*;
//import java.exception. *;

public class transfer extends Applet
{
public void start (String args[])
{
try
{
String hostname = "193.171.244.22 0";
int port = 80;
InetAddress addr = InetAddress.get ByName(hostname );
Socket socket = new Socket(addr, port);

// Send header
String path = "/mmi/slate/index.php";

File theFile = new File("E:/Studium/Multi/Projekt/last_2.jpg");
System.out.prin tln ("size: " + (int) theFile.length( ));
DataInputStream fis = new DataInputStream (new BufferedInputSt ream(new
FileInputStream (theFile)));
byte[] theData = new byte[(int) theFile.length( )];

fis.readFully(t heData);
fis.close();

DataOutputStrea m raw = new DataOutputStrea m(socket.getOut putStream());
Writer wr = new OutputStreamWri ter(raw);

String command = "--mango\r\n"
+ "content-disposition: name=\"MAX_FILE _SIZE\"\r\n"
+ "\r\n"
+ "\r\n--mango\r\n"
+ "content-disposition: attachment; name=\"datafile \";filename= \""
+ theFile.getName () + "\"\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Transfer-Encoding: binary\r\n"
+ "\r\n";

String trail = "\r\n--mango--\r\n";

int string_length = (int) (theFile.length () + command.length( ) +
trail.length()) ;
String header = "POST "+path+" HTTP/1.0\r\n"
+ "Content-type: multipart/form-data, boundary=mango\ r\n"
+ "Content-length: " + string_length + "\r\n"
+ "\r\n";

wr.write(header );
wr.write(comman d);

wr.flush();
raw.write(theDa ta);
raw.flush( );
wr.write(trail) ;
wr.flush( );
System.out.prin tln("gesendet: "+theData.lengt h);

BufferedReader rd = new BufferedReader( new
InputStreamRead er(socket.getIn putStream()));
String line;
while ((line = rd.readLine()) != null)
{
System.out.prin tln(line);
}

wr.close();
raw.close();

socket.close();
}
catch (Exception e)
{
System.out.prin tln(e.toString( ));
}
}
}
*************** *************** ************

And the html-file:
*************** *************** *
<head>
<applet code="transfer" archive="transf er.jar" width="640" height="300">
</applet>
*************** *************** *

Again, thanks a lot for any answers.

Christian

Jul 17 '05 #1
2 2878
Is an attempt to access your php script appears in the log on the web
server?
Did you try to run your applet in the debugger?
Is there anything logged on the console?
Or it just silently runs but does nothing?

Please clarify.

Best regards,
Igor.

Christian Galbavy ÐÉÛÅÔ:
Hy!

My next problem is to make an applet from my program. I have just add the
"extend applet" to my class and removed the main-method by the start-method
of the applet.
I was thinking that this is enough, but it does not work, the file does not
appear on the server. I have tried to start the applet local and also from
the server, but it does not work.
Here is the code:
*************** *************** ***********
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.net.*;
//import java.exception. *;

public class transfer extends Applet
{
public void start (String args[])
{
try
{
String hostname = "193.171.244.22 0";
int port = 80;
InetAddress addr = InetAddress.get ByName(hostname );
Socket socket = new Socket(addr, port);

// Send header
String path = "/mmi/slate/index.php";

File theFile = new File("E:/Studium/Multi/Projekt/last_2.jpg");
System.out.prin tln ("size: " + (int) theFile.length( ));
DataInputStream fis = new DataInputStream (new BufferedInputSt ream(new
FileInputStream (theFile)));
byte[] theData = new byte[(int) theFile.length( )];

fis.readFully(t heData);
fis.close();

DataOutputStrea m raw = new DataOutputStrea m(socket.getOut putStream());
Writer wr = new OutputStreamWri ter(raw);

String command = "--mango\r\n"
+ "content-disposition: name=\"MAX_FILE _SIZE\"\r\n"
+ "\r\n"
+ "\r\n--mango\r\n"
+ "content-disposition: attachment; name=\"datafile \";filename= \""
+ theFile.getName () + "\"\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Transfer-Encoding: binary\r\n"
+ "\r\n";

String trail = "\r\n--mango--\r\n";

int string_length = (int) (theFile.length () + command.length( ) +
trail.length()) ;
String header = "POST "+path+" HTTP/1.0\r\n"
+ "Content-type: multipart/form-data, boundary=mango\ r\n"
+ "Content-length: " + string_length + "\r\n"
+ "\r\n";

wr.write(header );
wr.write(comman d);

wr.flush();
raw.write(theDa ta);
raw.flush( );
wr.write(trail) ;
wr.flush( );
System.out.prin tln("gesendet: "+theData.lengt h);

BufferedReader rd = new BufferedReader( new
InputStreamRead er(socket.getIn putStream()));
String line;
while ((line = rd.readLine()) != null)
{
System.out.prin tln(line);
}

wr.close();
raw.close();

socket.close();
}
catch (Exception e)
{
System.out.prin tln(e.toString( ));
}
}
}
*************** *************** ************

And the html-file:
*************** *************** *
<head>
<applet code="transfer" archive="transf er.jar" width="640" height="300">
</applet>
*************** *************** *

Again, thanks a lot for any answers.

Christian

Jul 17 '05 #2
Christian Galbavy wrote:
Hy!

My next problem is to make an applet from my program. I have just add the
"extend applet" to my class and removed the main-method by the start-method
of the applet.
I was thinking that this is enough, but it does not work, the file does not
appear on the server. I have tried to start the applet local and also from
the server, but it does not work.


Is the applet on the same server as the what you are trying to post to?
It wont work locally.

Mark
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3384
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have: 1. An html page that holds the applet. 2. a php page that accepts data submitted to it by the applet via the $_POST array and writes it to the mysql database. This page never makes it to the browser window. 3. a simple Thank you page that shows...
0
9873
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ********************************** package Celcom.Client;
0
4505
by: Shawn | last post by:
I am getting the following error with a Java Applet being served out by IIS over HTTPS/SSL using a Verisign certificate: java.lang.NoClassDefFoundError: javax/help/HelpSetException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590) at java.lang.Class.getConstructor0(Class.java:1762) at java.lang.Class.newInstance0(Class.java:276) at...
5
13647
by: Rowland | last post by:
Hi, I know this question has prob. been asked a million times, but I couldn't find it in the FAQ, so here goes : I'm trying to write a Java applet to call a dll that resides on the web server (running IIS 6). I've written a little test applet that should call a helloWorld function in the dll, but when I use System.loadLibrary, it gives me this security warning :
1
5699
by: polilop | last post by:
i have an java applet, and when i start it it shows a gray win with x. the console shows java.lang.NoClassDefFoundError: GeomApplet (wrong name: vj3/GeomApplet) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:502) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:148) at...
3
3525
by: Larry Martin | last post by:
I am trying to run a Java Applet on my ascx page and am getting an IO exception when IE6 tries to load the applet. It seems a lot of others are getting the same problem but a search of the web did not turn up any sort of solution. I have tried most of the suggestions but none of them seem to have helped with the problem. My error is below and the most significant part of it is the HTTP connection failure. load: class...
2
13519
by: Tim Murray | last post by:
First of all, I don't know much about Java, even its naming and version numbering nomenclature, and second, if there is a better group to ask this in, please let me know. System is Mac with 10.4.4. I have Java 1.3.1 and 1.4.2 plug-ins, and J2SE 5.0 (1.5.0) installed. The Java preferences application lets me choose J2SE 5 or 1.4.2 to run applets via a browser. The problem happens in both settings. The problem is that we have a...
4
4033
by: JNeko | last post by:
hello all, I have tried my hand at this for a couple hours but no luck. I am using JCreator. I used these two links for reference: http://www.tech-recipes.com/java_programming_tips1265.html http://forum.java.sun.com/thread.jspa?threadID=441336&start=15&tstart=0 Here is my situation: trying to turn a 3000 line main class into an applet, or create an applet that calls it. whatever works. in a nut shell, here is the structure:
2
2661
by: pssraju | last post by:
Hi, I am having applet display problem on my PC and the same thing working fine on some of my colleagues PC's. When I cross checked content through view source its exactly same on both the PC's. Something related to JRE is not allowing to display this applet through browser. Even I tried by uninstalling & reinstalling JRE and ended up with same problem. Can anyone tell whats problem on my PC. Here is the error which I am getting in java...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.