Using the Httpservice method in flex to interact with Java

Source: Internet
Author: User
Tags xmlns root directory tomcat

  This article mainly introduces the use of flex in the Httpservice method to interact with Java, the need for friends can refer to the following

The earth has been moved to a state of vibration. Use the Httpservice method in flex to interact with Java:    write server:  1. Create a Web project   2 in MyEclipse. Write a servlet  for printing XML 3. When interacting with Java using Httpservice, you do not need to overwrite the access address of the Remoting-config.xml file   4.web.xml file to configure the servlet ( Generally do not configure, when a servlet is built MyEclipse will automatically configure the Web.xml file, do not have to change, but it should be noted that When you import blazeds development file, he will change Web.xml file, at this time you must be web.xml file change, otherwise flex in access to the server when you can not ask your servlet.   5. When your server-side servlet is written, set up a flex project, and configure the Flex server's access address in the Flex project's property entries based on your previously built servlet project.   6. Write Flex mxml files.     Second simple case:  1.servlet source code     code as follows: Package Com.wle.flex.HttpService.java file source code     Package com.wle.flex;    Import java.io.ioexception;  import java.io.writer;    Import javax.servlet.servletexception;  Import javax.servlet.http.httpservlet;  Import javax.servlet.http.httpservletrequest;  Import javax.servlet.http.httpservletresponse;    Public Class HttpService01 extends HttpServlet {    public void doget (HttpServletRequest request, HttpServletResponse response)   throws Servletexception, IOException {    Response.setcontenttype ("text /xml;charset=utf-8 ");  Writer out = Response.getwriter ();  out.write (<?xml version= ' 1.0 ' encoding= ' Utf-8 '?> ');  out.write ("<item>");  out.write ("<student name= ' Lin ' an ' age= ' class= '" "Water park Liangshan yi ban)/> ");  out.write (" <student name= ' Likui ' age= ' class= ' "Water park Liangshan second class '/> ');  out.write (" <student name= ' 扈三娘 ') " Age= ' class= ' Water park Liangshan one class '/> ');  out.write ("<student name= ' when moved ' age= '" ' class= ' water park Liangshan second class '/> ');  Out.write ("<student name= ' Wu Song ' age= ') ' class= ' Water park Liangshan one class '/> ');  out.write (" <student name= ' 燕青 ' age= ' 24 ') Class= ' Water park Liangshan second class '/> ');  out.write ("</item>"); }  public void DoPost (HttpServletRequest request , httpservletresponse response)   throws Servletexception IOException {  (Request, this.doget);  } }    2.servlet corresponds to the Web.xml file   code as follows: <?xml version= "1.0" Encoding= "UTF-8"?>  <web-app version= "3.0"   xmlns= "Http://java.sun.com/xml/ns/javaee"   xmlns: Xsi= "http://www.w3.org/2001/XMLSchema-instance"   xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee   Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd ">  <display-name></display-name>   <servlet>  <description>this is the description of my Java component</description>  & Lt;display-name>this is the display name of my Java EE component</display-name>  <servlet-name> httpservice01</servlet-name>  <servlet-class>com.wle.flex.HttpService01</servlet-class>   </servlet>    <servlet-mapping>  <servlet-name>httpservice01</ servlet-name>  <url-pattern>/wl/HttpService01</url-pattern>  </servlet-mapping>     </web-app>    3. Import blazeds file in Webroot directory     4. Post Servlet project   For example, Servlet projectPost to D:tomcat 6.0webappsflex_service_httpservice this file     5. Set up Flex Project   Build Flex project, right-click on Project to select Properties, Set the flex server's address   configuration information as follows:  file root in the Flex server option in properties: D:tomcat 6.0webappsflex_service_httpservice  root url (U) :http://localhost:8089/flex_service_httpservice  Context root directory:/flex_service_httpservice  6. After you configure the server for the Flex project, you begin to write the flex source file, as follows:  code: <?xml version= "1.0" encoding= "Utf-8"?>  <mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml"   layout= "vertical"   fontsize= "viewsourceurl=" srcview/ Index.html "xmlns:s=" Library://ns.adobe.com/flex/spark ">    <!--<mx:style source=" Dgtoexcel.css "/>-->      <mx:Script>  <! [cdata[  Import mx.collections.arraycollection;  Import mx.controls.alert;  Import mx.events.flexevent;  Import mx.events.itemclickevent;  Import mx.rpc.events.faultevent;    [ bindable]  private var myac:arraycollection;    Private function Faulthandler (event:faultevent):void  {  alert.show (event.fault.faultString, Event.fault.message);  }   //Function to filter out all items with gender  private Function Malefilterfunc (item:object): Boolean {  return Item.gender = = 1; }   //function to apply the filter function the icollectionview.  Private Function Filtermale (): void {  myac.filterfunction = malefilterfunc; //refresh The collection view to AP Ply the filter.  Myac.refresh (); }   /Function to filter out all items with gender  private F Unction Femalefilterfunc (item:object): Boolean {  return item.gender = 0; }   //Function to apply T He filter function The icollectionview.  private function Filterfemale (): void {  myac.filterfunction = Femalefi lterfunc; //refresh The collection view to apply the filter.  Myac.refresh (); }   /Function To Reset the view to its OriginaL state.  Private Function Resetac (): void {  myac.filterfunction = null; //refresh the collection VIEW.&NB Sp Myac.refresh (); }     /Event handler function to display the selected button  private functio n Filterhandler (event:itemclickevent): void {  switch (event.currentTarget.selectedValue) {  case 1:  Filtermale ();  break;  case 0:  Filterfemale ();  break;  case 2:  ResetAC ();  the break;   default:  break; }   }    protected function Bt1_clickhandler ():void  {   Myservice.send (); }   ]]>  </mx:Script>  <mx:httpservice id= "MyService"   Showbusycursor= "true"   url= "HTTP://LOCALHOST:8089/FLEX_SERVICE_HTTPSERVICE/WL/HTTPSERVICE01"   result= "Myac = event.result.item.student"   fault= "Faulthandler (event)"   contenttype= "Application/xml"  />  <mx:HBox>  <mx:radiobuttongroupId= "Gendertype" itemclick= "Filterhandler (event);" />  <mx:radiobutton groupname= "Gendertype" id= "Rbmale" value= "1" label= "male"/>  <mx:RadioButton Groupname= "Gendertype" id= "Rbfemale" value= "0" label= "female"/>  <mx:radiobutton groupname= "Gendertype" Rball "value=" 2 "label=" All "/>  </mx:HBox>  <mx:datagrid id=" MYDG "width=" 100% "rowcount=" 20 "   dataprovider= "{Myac}" >  <mx:columns>  <mx:datagridcolumn headertext= "name" datafield= " Name "/>  <mx:datagridcolumn headertext= Age" datafield= "ages"/>  <mx:datagridcolumn "Class" Datafield= "Class"/>  </mx:columns>  </mx:DataGrid>  <mx:HBox>  <s: Button id= "BT1" label= "Submit" click= "Bt1_clickhandler ()"/>  </mx:HBox>  </mx:Application>     This enables the interactive work of Flex to Java EE  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.