• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

debug code applet servlet communication

 
mani suri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all
I am facing a problem in applet servlet communication , i am enclosing two code for applet servlet communication . It is giving me EOF Exception .
Please help me debuuging it.its urgent
enclosed codes are :
//Applet Code
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
public class sappletm1 extends Applet implements ActionListener
{
private String message;
TextField t;
Label l;
Button b;
Image ash;
URLConnection uc = null;
String text;
public void init()
{
t = new TextField(20);
l = new Label("Search");
b = new Button("Press");
b.addActionListener(this);
add(l);
add(t);
add(b);
try
{
uc = new URL("http://localhost:8080/servlet/ServletAppletm1").openConnection();
uc.setUseCaches(false);
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setRequestProperty("Content-type", "application/octet-stream");
uc.connect();
}
catch(Exception e)
{
message = e.toString()+"first";
repaint();
}

}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b)
{
text = t.getText();

try
{
ObjectOutputStream objOu = new ObjectOutputStream(uc.getOutputStream());
objOu.writeObject(text);
objOu.flush();
objOu.close();
}

catch(Exception e)
{
message = e.toString()+"second";
repaint();
}

try
{

ObjectInputStream objIn = new ObjectInputStream(uc.getInputStream());
message = (String) objIn.readObject();
t.setText("");
repaint();
}
catch(Exception e)
{
message= e.toString()+""+"third ";
repaint();
}
}
}

public void paint(Graphics g)
{
g.drawString (message, 25, 75);
// g.drawString (text, 25, 75);
//g.drawImage(ash,0,0,this);
}
}

--------------------------------------------------------------------------------------------------------------------------------
//Servlet code

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ServletAppletm1 extends HttpServlet
{
String message,client,mani;
Statement s;
Connection c;
PreparedStatement p;
ResultSet rs;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c= DriverManager.getConnection("jdbc dbc:mapping");
s = c.createStatement();
}
//_______________________try ends____________________
catch(Exception ee)
{
System.out.println("Check your dsn connection!"+ee);
}
}

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("application.octet-stream");
try
{
ObjectInputStream objIn = new ObjectInputStream(req.getInputStream());
client = (String) objIn.readObject();

}
catch(Exception e)
{
e.printStackTrace();
}
try
{
rs.next();
rs = s.executeQuery("select imgsource from map where colony = '" + client + "'");
mani = rs.getString("imgsource");

if (mani!=null)
{
ObjectOutputStream objOu = new ObjectOutputStream(res.getOutputStream());
objOu.writeObject(mani);
objOu.close();
}
else
{

ObjectOutputStream objOu = new ObjectOutputStream(res.getOutputStream());
objOu.writeObject("your mani is null");
objOu.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
______________________________________________________________________
The gives me problem when i press the button it diaplays the Exception (EOFEXCEPTION). I want when i press the button the applet text field contents should go to servlet and servlet while checking into the data base so give path of the image .
the table i have construted in acess consist of two coloums one by the name of colony other by the name of imgsource.
waiting for your reply
thanks
mani
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic