This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes applet servlet problem 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 servlet problem" Watch "applet servlet problem" New topic
Author

applet servlet problem

daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hi freinds,
ive been trying applet-servlet- database thing with object serilization, when i made a simple program with just 3 fields it was working fine and now when i increased the fields it is not working and the java console is giving file not found error for the servlet while it was working fine earlier and of course the file is there, Im pasting the code of applet here , plz try and see if u can help me,
Regards,
Daman
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
/*<applet code=TestApplet.class width=300 height=200>
</applet>*/
public class TestApplet extends Applet implements ActionListener,Runnable
{
Panel top,middle,bottom;
Label lname, lage, lweight,ltelephone,laddress;
TextField name, age, weight,telephone,address;
TextArea display;
Button submit, clear,obtain;
String servletPath;
URL studentDBservlet;
URLConnection servletConnection;
private String webServerStr, protocol;
private String hostName="localhost";
private int port = 8080;
public void init()
{
this.setLayout(new BorderLayout());
top=new Panel();
top.setLayout(new GridLayout(6,2));
middle=new Panel();
middle.setLayout(new BorderLayout());
bottom=new Panel();
bottom.setLayout(new GridLayout(1,3));
servletPath="/servlet/DBServlet";
lname=new Label("Name");
lage=new Label("Age");
lweight=new Label("Weight");
ltelephone=new Label("Telephone");
laddress=new Label("Address");
name=new TextField();
age=new TextField();
weight=new TextField();
telephone=new TextField();
address=new TextField();
display=new TextArea();
submit=new Button("Submit");
clear=new Button("Clear");
obtain=new Button("Obtain");
submit.addActionListener(this);
clear.addActionListener(this);
obtain.addActionListener(this);
top.add(new Label("Registration Form"));
top.add(new Label());
top.add(lname);
top.add(name);
top.add(lage);
top.add(age);
top.add(lweight);
top.add(weight);
top.add(ltelephone);
top.add(telephone);
top.add(laddress);
top.add(address);
middle.add(display);
bottom.add(submit);
bottom.add(clear);
bottom.add(obtain);
add(top,BorderLayout.NORTH);
add(middle,BorderLayout.CENTER);
add(bottom,BorderLayout.SOUTH);
setVisible(true);
URL hostURL = getCodeBase();
protocol=hostURL.getProtocol();
hostName = hostURL.getHost();
port = hostURL.getPort();
if (port == -1)
{
port = 80;
}
webServerStr = "http://"+hostName+":"+port+servletPath;
try
{
studentDBservlet = new URL(webServerStr);
System.out.println(webServerStr);
servletConnection = studentDBservlet.openConnection();
// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't used a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches(false);
// Specify the content type that we will send binary data
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
Thread t=new Thread(this);
t.start();
}
catch(Exception e)
{
System.out.println("Exception in constructor"+e);
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==clear)
{
name.setText("");
age.setText("");
weight.setText("");
telephone.setText("");
address.setText("");
}
if(ae.getSource()==submit&&!name.getText().trim().equals("")&&!age.getText().trim().equals("")&&!weight.getText().trim().equals("")&&!telephone.getText().trim().equals("")&&!addres s.getText().trim().equals(""))
{
try
{
Student objStudent=new Student(name.getText(),Integer.parseInt(age.getText()),new Double(weight.getText()).doubleValue(),Integer.parseInt(telephone.getText()),address.getText());
System.out.println("name "+objStudent.getName()+" age "+objStudent.getAge()+" weight "+objStudent.getWeight()+" telephone "+objStudent.getTelephone()+" address "+objStudent.getAddress());
ObjectOutputStream oos=new ObjectOutputStream(servletConnection.getOutputStream());
oos.writeObject(objStudent);
oos.flush();
oos.close();
}
catch(Exception e)
{
System.out.println("exception in comtacting host "+e);
}
}
}
public void run()
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
while(true)
{
String read=in.readLine();
if(read==null)
return;
display.append(read);
}
}
catch(Exception e)
{
System.out.println("Exception in reading "+e);
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet servlet problem
 
Similar Threads
method not abstract
. . .not abstract and doesnt overide abstract method actionPerfomed
HttpURLConnection.
Security Errors
security problem in applets