hello,
I've written an applet that works fine in appletviewer but when I try it on my webserver it says it can't load the class file. i've tried just on a browser with the html file nad the class file in the same directory but that won't work either. it seems I can't attach the file(.java is'nt allowed) so I've just copied and pasted it underneath. any help would be greatly appreciated.

thanks

adunkey

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.math.BigInteger;
import java.lang.Character.*;
import javax.swing.*;
/** Applet that reads userName, password, and
* emailAddress parameters, ElGamals the password
* and sends userName number1,number2, and Email via
* POST to the host, port, and URI specified.
*
*/
/*
Author: TD ( base class from MArty Hall (http://www.coreservlets.com/.)
Rev: 1.1
Date: 17/04/02
Rev history: 1.2 Clean it up
set k to be a random variable
lose the prints
check the password has been successfully stored
receive.pl will need amending
1.1 adding hte ElGamal component t the basic set up
1.0 Getting he basic communication up and running
*/
/*
Important information
Connection information: Location : ActionPerformed()
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
String uri = "/cgi-bin/script/receive.pl";
String portString = String.valueOf(currentPage.getPort());
*/
public class SecPost extends JApplet
implements ActionListener {
private JTextField userNameField,
emailAddressField, hostField,
portField,statusField, uriField;
private JPasswordField passwordField;
private JLabel pass, user, email,stats;
private JButton sendButton;
private JTextArea resultsArea;
private BigInteger gk,Pgak ;
URL currentPage;
public void init() {
gk = new BigInteger("0");
Pgak = new BigInteger("0");
setBackground(Color.white);
getContentPane().setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(9, 1));
inputPanel.setFont(new Font("Serif", Font.BOLD, 14));
user = new JLabel("USER NAME");
inputPanel.add(user);
userNameField =
new JTextField("", 15);
inputPanel.add(userNameField);
pass = new JLabel("PASSWORD");
inputPanel.add(pass);
passwordField =
new JPasswordField("", 15);
inputPanel.add(passwordField);
email = new JLabel("EMAIL ADDRESS ");
inputPanel.add(email);
emailAddressField =
new JTextField("", 25);
inputPanel.add(emailAddressField);
stats = new JLabel("PASSWORD STATUS");
inputPanel.add(stats);
statusField =
new JTextField("", 25);
statusField.setText("Password not sent yet");
inputPanel.add(statusField);
JPanel separator1 = new JPanel();
inputPanel.add(separator1);
currentPage = getCodeBase();
// getHost returns empty string for applets from local disk.
//Canvas separator2 = new Canvas();
//inputPanel.add(separator2);
sendButton = new JButton("Submit Data");
sendButton.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(sendButton);
inputPanel.add(buttonPanel);
getContentPane().add(inputPanel, BorderLayout.NORTH);
setSize(600,300);
String resultsMessage = " confirmation of registration will appear here deedum";
resultsArea = new JTextArea();
resultsArea.setText(resultsMessage);
//add(resultsArea, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent event) {
try {
// here are the connection parameters
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
String uri = "/cgi-bin/receive.pl";
String portString = String.valueOf(currentPage.getPort());
int port;
try {
port = Integer.parseInt(portString);
} catch(NumberFormatException nfe) {
port = -1; // I.e., default port of 80
}
// Here we must encrypt the password to get the ElGamal numbers
String password = new String(passwordField.getPassword());
Elencrypt(password);
System.out.println( "past Elencrypt Pgak value in "+Pgak.toString());
System.out.println( "encoded version is " +URLEncoder.encode(Pgak.toString()) );
// NB this has set the values of gk and Pgak
URL dataURL = new URL(protocol, host, port, uri);
URLConnection connection = dataURL.openConnection();
// Make sure browser doesn't cache this URL.
connection.setUseCaches(false);
// Tell browser to allow me to send data to server.
connection.setDoOutput(true);
ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(512); // Grows if necessary
// Stream that writes into buffer
PrintWriter out = new PrintWriter(byteStream, true);
System.out.println(" the parameter value of gk is "+URLEncoder.encode(gk.toString()) );
System.out.println(" the parameter value of Pgak is "+URLEncoder.encode(Pgak.toString()) );
String postData =
"userName=" + encodedValue(userNameField) +
"&gk=" + URLEncoder.encode(gk.toString()) +
"&Pgak=" + URLEncoder.encode(Pgak.toString()) +
"&emailAddress=" + encodedValue(emailAddressField);
statusField.setText( "setting up parameters");
// Write POST data into local buffer
out.print(postData);
out.flush(); // Flush since above used print, not println
// POST requests are required to have Content-Length
String lengthString =
String.valueOf(byteStream.size());
connection.setRequestProperty
("Content-Length", lengthString);
// Netscape sets the Content-Type to multipart/form-data
// by default. So, if you want to send regular form data,
// you need to set it to
// application/x-www-form-urlencoded, which is the
// default for Internet Explorer. If you send
// serialized POST data with an ObjectOutputStream,
// the Content-Type is irrelevant, so you could
// omit this step.
connection.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Write POST data to real output stream
byteStream.writeTo(connection.getOutputStream());
// let them know the passwords been sent
statusField.setText( "checking for server acknowledgement");
/* now we should confirm that the password has been successfully stored
We must snd something back form the perl script to this effect
The input Buffer willl pick it up and display it in the
Status field for us
*/
//System.out.println( "about to set up input stream reader");
BufferedReader in =
new BufferedReader(new InputStreamReader
(connection.getInputStream()));
System.out.println( "past input stream reader");
String line;
String linefeed = "\n";
//resultsArea.setText("");
statusField.setText( "");
while((line = in.readLine()) != null) {
statusField.setText(line);
//resultsArea.append(line);
// resultsArea.append(linefeed);
}
} catch(IOException ioe) {
// Print debug info in Java Console
System.out.println("IOException: " + ioe);
}
// now open a web page from the applet
try {
URL aURL = new URL("http://www.google.com");
getAppletContext().showDocument(aURL,"This is Google");
repaint();
}
catch (Exception e)
{
}
}
// TextField is really a Panel with a Label and
// TextField inside it. This extracts the TextField part,
// gets the text inside it, URL-encodes it, and
// returns the result.
private String encodedValue(JTextField field) {
String rawValue = field.getText();
return(URLEncoder.encode(rawValue));
}
private void Elencrypt(String password)
{
/* let's set up the two values gk and Pgak here
They are private members so are accessible from the method
*/
// Firstly our encryption data
BigInteger g = new BigInteger("3");
BigInteger ga = new BigInteger("27");
BigInteger n = new BigInteger("1331656851383141126634824735487135481");
BigInteger k = new BigInteger("2");
// ******************* to be changed to random *****************
BigInteger gak = new BigInteger("0");
BigInteger P = new BigInteger("0");
gk=g.modPow(k,n);
gak=ga.modPow(k,n);
P=toNumber(password);
System.out.println( " P value in encrypt is "+P);
Pgak=P.multiply(gak);
System.out.println( " Pgak value in encrypt is "+Pgak);
}
private BigInteger toNumber(String phrase)
{
/*
toNumber encodes a phrase to its number equivalent
Constraints: phrase should be at most 10 characters
This needs to corrspond with the undo on the server
*/
// Step 1 String to char array
int phraseLength = phrase.length();
char[] charArray = phrase.toCharArray();
// Step2 phrase to num equiv array eg tom -> 14,23,12
int count=0;
BigInteger P = new BigInteger("0");
BigInteger base = new BigInteger("256");
BigInteger basePow = new BigInteger("1");
BigInteger BigNumEquiv = new BigInteger("1");
int asciival = 0;
while(count<phraseLength)
{
asciival=(int)charArray[count]; // determines the ascii value of a char
BigNumEquiv = new BigInteger(""+asciival); // changes int to String
System.out.println( " ascii value is "+BigNumEquiv);
P=P.add(BigNumEquiv.multiply(basePow));
basePow=basePow.multiply(base);
count++;
}
return P;
}
}