its sending a
string and add hello to the string by the
servlet and returned to the
applet //applet
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
/*
<applet code="appservlet" width=100 height=100>
</applet>
*/
public class appservlet extends Applet{
TextField tf,tf1;
Button b1,b;
URLConnection uc;
public void init()
{
try {
tf=new TextField();
tf1=new TextField();
b=new Button("send");
b1=new Button("receive");
add(tf);
add(tf1);
add(b);
add(b1);
ButtonHandlerS bs=new ButtonHandlerS();
ButtonHandlerR br=new ButtonHandlerR();
b1.addActionListener(br);
b.addActionListener(bs);
}
catch(Exception ex)
{System.out.println(ex);}
}
void sendData()
{
try{
String queryString=tf.getText();
URL url=new URL("http://localhost:8080/servlet/srverapp");
uc=url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
String qry=URLEncoder.encode("qrl")+"="+URLEncoder.encode(queryString);
DataOutputStream dos=new DataOutputStream(uc.getOutputStream());
dos.writeBytes(qry);
dos.flush();
dos.close();}
catch(Exception ex)
{System.out.println(ex);}
}
void getData()
{
try{
InputStreamReader in=new InputStreamReader(uc.getInputStream());
int chr=in.read();
while (chr!=-1)
{
tf1.setText(String.valueOf((char)chr));
chr=in.read();
}
in.close();}
catch(Exception ex)
{System.out.println(ex);}
}
class ButtonHandlerS implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
sendData();
tf.setText("");
}
}
class ButtonHandlerR implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
getData();
}
}
}
//servlet
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class srverapp extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
String str=req.getParameter("qry");
PrintWriter pw=res.getWriter();
pw.println("hello"+str);
pw.println("<html><head><title>trial</title></head>");
pw.println("<body>str</body>");
pw.println("</html>");
}
catch(IOException ie)
{
System.out.println(ie);
}
}
}
using serveletrunner
error:FileNotFoundException:http://localhost:8080/servlet/srveapp
thankyou