File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Problem sending data from applet to servlet by object serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem sending data from applet to servlet by object serialization" Watch "Problem sending data from applet to servlet by object serialization" New topic

Problem sending data from applet to servlet by object serialization

rajeev raj

Joined: Jun 23, 2004
Posts: 1
Hi! all, i m using object serialization to send in data from my applet to servlet to be finally sent in to my database server. m very able to get data into applet from servlet which had been extracted from database server. m using nearly same code snipets for the two purposes. The code for applet to servlet is comliling with no errors but it showz IOException at runtime. I can't figure out why is it so?my data insertion activity from servlet to database is working fine i have checked. The problem seems to b in the passage of data from applet to servlet. Below are the code snippets for applet n the servlets. Anyone provide me with some clue plz.
Applet code snippet to pass data from applet to servlet:

String aname=name.getText(); // name is a text box.
URL url = new URL(getCodeBase(),"http://localhost:9090/examples/servlet/sendDataServ");
URLConnection servletConnection2=url.openConnection();
servletConnection2.setUseCaches (false);
servletConnection2.setDefaultUseCaches (false);
/*String see=servletConnection2.getContent().toString();
OutputStream os=servletConnection2.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
catch(Exception e){
System.out.println("no connection");

Code snippet of servlet:

public class sendDataServ extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String aname="";
InputStream in=req.getInputStream();
ObjectInputStream ois= new ObjectInputStream(in);
catch (IOException ioe)
catch (ClassNotFoundException cnfe)
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps= null;

try {
con = DriverManager.getConnection("jdbcdbc:test");
String sql="insert into try4(name) values (?)";
ps = con.prepareStatement(sql);
} catch (SQLException e) {
throw new
ServletException("Servlet Could not display records.", e);
} catch (ClassNotFoundException e) {
throw new
ServletException("JDBC Driver not found.", e);
} finally {
try {
if(rs != null) {
rs = null;
if(stmt != null) {
stmt = null;
if(con != null) {
con = null;
} catch (SQLException e) {}
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

It would help to see the stack trace of the exception. There may be another exception which causes the IOException.
The first thing to ask is are you downloading the applet from the same server that has the servlet? If not you will get a security exception.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Problem sending data from applet to servlet by object serialization
It's not a secret anymore!