 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mehmet F. Erten Guest
|
Posted: Wed Mar 07, 2007 5:38 am Post subject: APPLET TO SERVLET AND SERVLET TO APPLET |
|
|
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.
private void onSendData() {
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();
}
} |
|
| Back to top |
|
 |
Arthur Ore Guest
|
Posted: Thu Mar 08, 2007 2:36 am Post subject: Re: APPLET TO SERVLET AND SERVLET TO APPLET |
|
|
"Mehmet F. Erten" <mehmet_erten (AT) mblsoft (DOT) com> wrote in message
news:45edfb6b$1 (AT) newsgroups (DOT) borland.com...
| Quote: | 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
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();
}
} |
|
| Back to top |
|
 |
Mehmet F. Erten Guest
|
Posted: Thu Mar 08, 2007 5:35 am Post subject: To test the Servlet, Reboot is required. My Applet to Servle |
|
|
(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" <arthur_dot_ore (AT) nospamthx_zen_dot_co (DOT) uk> wrote in message
news:45ef221e (AT) newsgroups (DOT) borland.com...
| Quote: | "Mehmet F. Erten" <mehmet_erten (AT) mblsoft (DOT) com> wrote in message
news:45edfb6b$1 (AT) newsgroups (DOT) borland.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
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();
}
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|