|
-
JSP - Applet communication
Using servlets it is possible to setup a Servlet-Applet (or a Servlet-client
application in general) communication through http-post messages. Is there
anyway to do simular things with JSP, or is a Servlet still the preferred
way of setting up HTTP-post mechanisms?
-
Re: JSP - Applet communication
In article <399878bd$1@news.devx.com>, Jo Desmet <jo_desmet@yahoo.com> wrote:
>Using servlets it is possible to setup a Servlet-Applet (or a Servlet-client
>application in general) communication through http-post messages. Is there
>anyway to do simular things with JSP, or is a Servlet still the preferred
>way of setting up HTTP-post mechanisms?
Hi Jo,
The good news is that since JSPs are automatically converted into
servlets, anything you can do in one you can do in the other. In fact
there are several ways you can handle this sort of communication in a
JSP.
If your applet is sending form-like data (that is, name/value pairs
separated by ampersands) then you can just use beans to receive these
values directly. So, if your applet sends something like
"animal=fish&color=gold", and you have a bean named handler that has
setAnimal() and setColor() methods, then you can just include this in
your JSP:
<jsp:setProperty name="handler" property="*">
and everything will just work. Beans are cool...
Alternately, if your applet is sending some arbitrary data you can
handle it much as in a servlet. In a servlet you might do something
like:
InputStream in = request.getInputStream();
StringBuffer buffy = new StringBuffer();
byte data[] = new byte[1024];
int count;
while((count = in.read(data)) > 0)
buffy.append(new String(data,0,count));
in.close();
String postdata = buffy.toString();
You can do the same thing in a JSP by enclosing all of the above in a
<java></java> block. You could then send postdata to a bean with a
setPostdata() method. Or, you could move all of the above code into a
bean, and send the whole request to the bean with something like:
<jsp:setValue name="bean" property="request"
value="<%= request %>">
This is probably the cleanest option, at least for those building
pages. In either case, once the bean has the data, it can do whatever
it needs to with it, and then make other properties available to the
rest of the page.
Hope this helped!
- Larne
Similar Threads
-
By Rey Morejon in forum Java
Replies: 13
Last Post: 03-30-2008, 02:03 AM
-
By Gautham Kasinath in forum Java
Replies: 1
Last Post: 04-14-2006, 03:52 PM
-
By Charlie Flynn in forum Java
Replies: 3
Last Post: 08-23-2001, 11:01 AM
-
Replies: 1
Last Post: 08-10-2000, 12:35 PM
-
Replies: 1
Last Post: 08-10-2000, 12:33 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks