try {
URLConnection con = getServletConnection();
// get input data for sending
// send data to the servlet
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(jdbTextField1.getText());
oos.flush();
oos.close();
// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
System.out.println("result: " + result);
inputFromServlet.close();
instr.close();
// show result
jdbTextField1.setText(result);
}
catch (Exception ex) {
ex.printStackTrace();
exceptionArea.setText(ex.toString());
}
}
// here does not matter what I write, it does not affect above applet. It
reads its own input (again maybe from the servlet)
// I don't know how I can verify that my applet is actually sending and
reading from my servlet through the above code.
public void doPost(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
response.setContentType("application/x-java-serialized-object");
// read a String-object from applet
// instead of a String-object, you can transmit any object, which
// is known to the servlet and to the applet
echo = (String) new
ObjectInputStream(request.getInputStream()).readObject();
// echo it to the applet
ObjectOutputStream oos = new
ObjectOutputStream(response.getOutputStream());
oos.writeObject("mehmet" + echo);
oos.flush();
oos.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
Hi Mehmet,
I took some code from a working example I wrote a good while ago and tried
to make it match as closely as possible what you are trying to achieve.
I seem to recall that I found the following article very useful
http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html
I hopes this helps
Arth
// APPLET
try
{
URL postServlet = new URL(getCodeBase(),servletURL);
URLConnection servletConnection = postServlet.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
ObjectOutputStream out = new
ObjectOutputStream(servletConnection.getOutputStream());
out.writeObject( (Object) inputTextField.getText() );
out.flush();
out.close();
ObjectInputStream inputFromServlet = new
ObjectInputStream(servletConnection.getInputStream());
outputTextField.setText( (String) inputFromServlet.readObject() );
inputFromServlet.close();
}
catch (Exception ee)
{
ee.printStackTrace();
}
// SERVLET -------------------------------
public void doPost(HttpServletRequest request, HttpServletResponse
response)
{
try {
ObjectInputStream inputFromApplet = new
ObjectInputStream(request.getInputStream());
String fromApplet = null;
fromApplet = (String) inputFromApplet.readObject();
inputFromApplet.close();
System.out.println("Received from applet " + fromApplet);
ObjectOutputStream outputToApplet;
outputToApplet = new ObjectOutputStream(response.getOutputStream());
outputToApplet.writeObject(fromApplet + " added by servlet");
outputToApplet.flush();
outputToApplet.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
I got JBuilder code with the excellent GUI with very functional Applet to
Servlet connection thanks to the examples from WEB.
Now I will go and add QueryDataSet to work with Interbase through Servlet
from my Applet.
"Arthur Ore" <arthur_dot_ore@nospamthx_zen_dot_co.uk> wrote in message
news:45ef...@newsgroups.borland.com...