Calling servlets and JSPs from Flash
133
Calling a servlet or JSP
To call a servlet or a JSP defined as a servlet from ActionScript, use the servlet name specified in
the web application’s web.xml deployment descriptor file as an ActionScript function name. For
example, the servlet name is MyServlet in the following example:
function go_Clicked()
{
var pc:mx.remoting.PendingCall = servletService.MyServlet();
pc.responder = new RelayResponder( this, "MyServlet_Result",
"onCategoryFault" );
// etc.
}
The web.xml file contains the following servlet definition:
<servlet>
<servlet-name>
MyServlet
</servlet-name>
<display-name>MyServlet</display-name>
<description>Simple text servlet</description>
<servlet-class>MyServlet</servlet-class>
</servlet>
Note:
On Servlet 2.3-compliant application servers, you can define a JSP as a servlet by specifying a
JSP filename in a JSP-file element, rather than a servlet class in a servlet-class element.
Request arguments sent from Flash as parameters of the
ServletName()
function are available
from the Request scope as the parameter
"FLASH.PARAMS"
. You can return results to Flash using
the request parameter
"FLASH.RESULT"
, as shown in the following servlet:
import javax.servlet.*;
import java.io.IOException;
import java.util.List;
public class MyServlet implements Servlet
{
private String message = null;
public void init(ServletConfig config) throws ServletException
{
message = "Hello from MyServlet";
}
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
// The args could be used here too...
/*
Object o = request.getAttribute("FLASH.PARAMS");
if (o instanceof List)
{
List args = (List)o;
}
Object arg0 = args.get(0);
Object arg1 = args.get(1);
*/
request.setAttribute("FLASH.RESULT", message);
Содержание FLASH REMOTING MX
Страница 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...
Страница 8: ...8 Contents...
Страница 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...
Страница 142: ...142 Chapter 7 Using Flash Remoting for Java...