aspose file tools*
The moose likes Servlets and the fly likes some CODE here to work out!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "some CODE here to work out!!!!" Watch "some CODE here to work out!!!!" New topic
Author

some CODE here to work out!!!!

asheet anand
Ranch Hand

Joined: Nov 15, 2000
Posts: 83
hi everyone !!
i have made a program to communicate from a applet to a servlet
applet code
------------
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class client15 extends Applet implements ActionListener
{String a="yvooo";
TextField t1;
Button b1;
public void init()
{
t1=new TextField(10);
b1=new Button("Send");
add(t1);
add(b1);
t1.addActionListener(this);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{String s=t1.getText();
try{
URL xx=new URL("http://parminder:9000/cool/book5");
a="helloasd";
repaint();
URLConnection c = xx.openConnection();
c.setDoInput(true);
c.setDoOutput(true);
c.setUseCaches (false);
c.setDefaultUseCaches (false);
c.setRequestProperty ("Content-Type", "application/octet-stream");
DataOutputStream d;
d = new DataOutputStream(c.getOutputStream());
d.writeBytes(s);
d.flush();
d.close();
/*DataInputStream d1 = new DataInputStream(c.getInputStream());
a=d1.readLine();
repaint();
d1.close();*/
}catch(Exception e)
{a=("fdf"+e);
repaint();}}
public void paint(Graphics g)
{g.drawString(a,10,50);
}}
this code is working fine.i am getting the connection to the
servlet as :helloasd" is printed after i click the "send" button.

SERVLET code
-------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class book5 extends HttpServlet
{public void doGet(HttpServletRequest r,
HttpServletResponse r1)
throws ServletException, IOException
{DataInputStream d1;
d1=new DataInputStream(r.getInputStream());
String b=d1.readLine();
PrintWriter pw=r1.getWriter();
pw.println(b);}
}

(I am invoking the applet from a html file from the Browser.)
now when i run this servlet from browser window it gives a
READ TIMED OUT exception.even if i use doPost or service
method problem remains the same.
but when i remove the Comment from the applet and print
the input from the servlet in the applet it works fine
if i use "doPost" method in the servlet.
Infact then when i run the servlet 1st time it gives an
405 error but from next time it works fine.when i refresh
that Servlet window again an 405 error.
i know its a bit Confusing.but i'm confused too
Pleaseeeeeeee help me out.
thanks
asheet

Sagar Sharma
Ranch Hand

Joined: Aug 31, 2000
Posts: 92
hi,
i am as confused as you are. please ellaborate on the specific problem that u are facing. The code of the applet looks fine ... i think there is some problem with the servlet code (headers typically)...
sagar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: some CODE here to work out!!!!