To test the Servlet, Reboot is required. My Applet to Servlet codes are functional and works great.


2007-03-08 07:35:29 AM
jbuilder1
(I intented to reply to the group but looks like I sent it to Arthur only).
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" < XXXX@XXXXX.COM >wrote in message
Quote
"Mehmet F. Erten" < XXXX@XXXXX.COM >wrote in message
news:45edfb6b$ XXXX@XXXXX.COM ...
>Through the exampls I found from google search, I succeeded to
>communicate in between my applet and my servlet.
>(no more exception and/or messages which are related to the java security
>issues)
>But regardless how I modifed my applet sent data in my servlet, I keep
>reading same data from my servlet which is whatever my applet sents to
>the servlet.
>Thanks for any tip.

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
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();
}

}