Link to home
Start Free TrialLog in
Avatar of pattefar
pattefar

asked on

JSP+Applet

is it possible to transfer information from an applet (fx a string) to a JSP-page???? the transfer should start when i push a button on the applet.

if possible give a small and simple example.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Once the jsp page has got to the browser it is just plain old html, so there's not a lot of interacting you can do with it. You may be able to something with javascript.
What is it you want to do?
Avatar of pattefar
pattefar

ASKER

so this means that an applet can't send information to a JSP-page, but a html-page can, if you use a the form-tag??

how do i send information from javascript to the jsp-page, fx when i push a javascript-button?????is this even possible????
What is it exactly you want to do, we may have some terminology confusion.
applet and servlet can talk to each other.
and since JSP is just an abstraction of servlet..
probably its possible :).
yes, it is possible!

allow me some time to create some samples for you, it will be available tonight. :)

if you can't wait, I can explain a little bit for you.

in an HTML Page with Javascript, you can something like this:

...
<script Language="Javascript">
...
function setaction
{
 form1.action="xxx.jsp"
}
...
</script>
...
<form name='form1', method='post' action=''>
...
<input type=button name='b1' onclick='setaction()'>
...
</form>

so when you click the button 'b1', setaction() function is called and form1's action property is set to xxx.jsp.
and when the form1 is submitted(post), the xxx.jsp page is called and executed.

good luck
thx for the answers!!! could anybody give an example where i enter a string in a textfield in an applet and when i push a button on the applet, then the string is transferred to the jsp-page. the example don't have to include any javascript.
If you just want to load a jsp from your applet, then it's exactly the same as loading a html page from your applet.
from ur applet..

                   //  posting multiple Serialized objects to a Java servlet and getting objects  in return
     static public ObjectInputStream postObjects(URL servlet, Serializable objs[]) throws Exception
     {
          URLConnection con = servlet.openConnection();
          con.setDoInput(true);
          con.setDoOutput(true);
          con.setUseCaches(false);
          con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

          // Write the arguments as post data
          ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
          int numObjects = objs.length;
          for (int x = 0; x < numObjects; x++) {
               out.writeObject(objs[x]);
          }

          out.flush();
          out.close();

          return new ObjectInputStream( con.getInputStream() );
     }

from ur servlet...

     public void doPost(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException
     {
          // Open the I/O streams
          ObjectInputStream in = new ObjectInputStream(req.getInputStream() );
          ObjectOutputStream out = new ObjectOutputStream( resp.getOutputStream() );
          try {
               // 1. Read in parameters from the applet
               String id = (String)in.readObject();
               UserData data = (UserData)in.readObject();

               // 2. Execute the RMI call
               db.editUser(id, data);

               // 3. Write the result
               // [no return value]

          } catch (Exception e) { e.printStackTrace(); }

          // Close the I/O streams
          in.close();
          out.close();
     }

this is not my code.. just copy pasted it.

look for the article in javasoft.com for :
Java Servlets and Serialization with RMI
OR get the book by jason hunter 'Java Servlet Programming'

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points NOT refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial