4 Replies Latest reply on Aug 14, 2007 10:33 AM by levancho

    JSP-FLEX-SERVLET

    sandeepmkumar
      hi,
      my name is sandeep. please help me to solve this issue,

      currently i have a login.jsp in which i am calling source="./login.mxml"
      code for login.jsp
      /**********************************/
      <%@ taglib uri="FlexTagLib" prefix="mm" %>
      <html>
      <head>
      <title>This is calling HelloServlet</title>
      </head>
      <body>
      <form action=./HelloServlet method=POST>
      <mm:mxml source="./Login.mxml">

      </mm:mxml>
      </form>
      </body>
      </html>
      /*********************************/

      and code in login.mxml
      /*****************************************************/
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >
      <mx:Panel width="382" height="315" layout="absolute" horizontalCenter="4" verticalCenter="2.5" fontFamily="Verdana" title="eCTDViewer-Login">

      <mx:Label x="25" y="49" text="UserName "/>
      <mx:TextInput x="115" y="47"/>
      <mx:Text x="25" y="98" text="Password"/>
      <mx:TextInput x="115" y="96" displayAsPassword="true"/>
      <mx:Button label="Login" horizontalCenter="-80" verticalCenter="42.5" textRollOverColor="#408080" />
      <mx:Button x="186" y="169" label="Cancel" textRollOverColor="#408080"/>
      <mx:Label x="10" y="-26" text="eCTDViewer-Login" width="310" height="23" enabled="true"/>
      </mx:Panel>

      </mx:Application>
      /**************************************************************/

      and in now i am calling login.jsp in IE 7.0 as url= http://localhost:8080/flex/login.jsp

      it is displaying login page exactly what i want, but after entering username,password when i click submit button it should go to HelloServlet, there in servlet i am just printing a message,
      but it is not going to HelloServlet, Please guide me how to do this. and what need s to be configured in web.xml,

      /**********************HelloServlet**************/

      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.HttpServlet;

      public class HelloServlet extends GenericServlet {

      public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
      {
      res.setContentType("text/html");
      PrintWriter pw=res.getWriter();
      System.out.println("I can into HelloServlet");
      pw.println("<B>Hello!");
      pw.println("<B>Hi!");
      pw.close();
      }

      }

      }
      /**********************************************/
      /***********************web.xml**************/

      <?xml version="1.0" encoding="utf-8"?>
      <web-app id="WebApp_ID" version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <servlet>
      <servlet-name>login</servlet-name>
      <servlet-class>HelloServlet</servlet-class>
      </servlet>
      <servlet-mapping>
      <servlet-name>login</servlet-name>
      <url-pattern>/login</url-pattern>
      </servlet-mapping>
      </web-app>
      /******************************************/

      Please give me an example/code if possible
      waiting for reply.

      your sandeep.
      sandeep_mk2003@yahoo.com
        • 1. JSP-FLEX-SERVLET
          kcell Level 2
          Hi Sandeep,

          I am not an expert of jsp, but I think there is no logic connection between the login button (the mxmxl) and your "Hello Servlet" servlet.

          Found one example here, where a HTTPService is used to call the servlet:
          http://flexblog.faratasystems.com/?p=143
          http://flexblog.faratasystems.com/?p=79

          best regards,
          kcell

          • 2. Re: JSP-FLEX-SERVLET
            kcell Level 2
            after you posted the question in 3 different forums entries I will try to give you an example how your code can look like (I have not tested it):
            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >

            <mx:HTTPService id="yourServlet" useProxy="false" method="POST"
            url=" http://localhost:8080/flex/helloservlet.jsp" result="onResult(event)" />

            <mx:Panel width="382" height="315" layout="absolute" horizontalCenter="4" verticalCenter="2.5" fontFamily="Verdana" title="eCTDViewer-Login">

            <mx:Label x="25" y="49" text="UserName "/>
            <mx:TextInput x="115" y="47"/>
            <mx:Text x="25" y="98" text="Password"/>
            <mx:TextInput x="115" y="96" displayAsPassword="true"/>
            <mx:Button label="Login" horizontalCenter="-80" verticalCenter="42.5" textRollOverColor="#408080" click="submitForm()" />
            <mx:Button x="186" y="169" label="Cancel" textRollOverColor="#408080"/>
            <mx:Label x="10" y="-26" text="eCTDViewer-Login" width="310" height="23" enabled="true"/>

            <mx:Script>
            <![CDATA[

            import mx.controls.Alert;

            private function submitForm():void {
            yourServlet.cancel();
            yourServlet.send(); // you can also send some parameters here
            }

            private function onResult(event:Event):void{
            trace(’Got the result’); // works only in the debug mode
            return;
            }
            ]]>
            </mx:Script>
            </mx:Panel>

            • 3. Re: JSP-FLEX-SERVLET
              sandeepmkumar Level 1
              Hi kcell,

              i dont no you are Mr Mrs.

              finally i did here my code goes, my be helpfull to others dude,

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:HTTPService id="myService" url=" http://localhost:8080/Sample/HelloServlet" useProxy="false">
              <mx:request>
              <username>
              {user.text}
              </username>
              <password>
              {pwd.text}
              </password>
              </mx:request>
              </mx:HTTPService>

              <mx:Script>
              <![CDATA[
              import mx.messaging.messages.HTTPRequestMessage;
              import mx.controls.Alert;

              public function submitForm(f:Form):void
              {
              myService.cancel();
              myService.method = "POST";

              // var params:Object = new Object();
              // params.uName = user.text;
              //params.pWord =pwd.text;
              myService.send();

              }
              ]]>
              </mx:Script>
              <mx:Panel x="97.5" y="74" width="403" height="372" layout="absolute">
              <mx:Form x="10" y="10" width="363" height="208" id="form1">
              <mx:Grid width="293" height="171">
              <mx:GridRow width="100%" height="32">
              <mx:GridItem width="84" height="20">
              <mx:Label text="User Name" width="73"/>
              </mx:GridItem>
              <mx:GridItem width="100%" height="22">
              <mx:TextInput width="193" id="user"/>
              </mx:GridItem>
              </mx:GridRow>
              <mx:GridRow width="100%" height="29">
              <mx:GridItem width="78" height="100%">
              <mx:Label text="Pass word" width="84"/>
              </mx:GridItem>
              <mx:GridItem width="199" height="100%">
              <mx:TextInput width="195" displayAsPassword="true" editable="true" id="pwd"/>
              </mx:GridItem>
              </mx:GridRow>
              <mx:GridRow width="100%" height="37">
              <mx:GridItem width="74" height="100%">
              </mx:GridItem>
              <mx:GridItem width="199" height="29">
              <mx:Button label="Submit" labelPlacement="left" enabled="true" width="104" click="submitForm(form1)"/>
              <mx:Button label="Cancel" labelPlacement="right" width="84"/>
              </mx:GridItem>
              </mx:GridRow>
              </mx:Grid>
              </mx:Form>
              </mx:Panel>
              </mx:Application>

              and in HelloServlet i am just displaying it , thats it ,

              thanks for your reply,

              with regards
              sandeep.
              • 4. Re: JSP-FLEX-SERVLET
                levancho Level 3
                1) "submitForm(form1)" should be "submitForm()" or "submitForm(event)"(if you want event obj with it .


                MX:FORM has nothing to do with HTML FORM control and it does not do anything magic besides layout, so in your case "submitForm(form1)" and "submitForm()" is same thing .


                2) your example is almsot useless unless you have resultHandler , otherwise how do you know what happened with the service?
                so something along the ways of === result="onResult(event)" is a MUST.

                to summarize :

                your example is not complete and Not correct.

                kcell is correct and good example.