8 Replies Latest reply on Aug 29, 2008 5:24 AM by ac361

    Flex with JSP

      Hi All,
      am new to Flex.Here is the simple scenario that am not able to make it work, how to get the values from the form(from MXML file) in JSP and validating the form(for manadatory fields) and storing those values in database and getting those details back and diaplaying with the MXML file.

      Thanks in Advance.
        • 2. Re: Flex with JSP
          Level 1

          Hi,

          Thanks for your help JB2622 .

          Earlier also i got the same example from the net but in that just they mentioned the file name. Now after deploying that file in the Tomcat server and changing the URL

          employee.jsp to http://localhost:8080/employee.jsp

          it is working fine now.


          • 3. Re: Flex with JSP
            JimBrychka Level 1
            You should not have to use the whole URL. Have you tried "/employee.jsp"?
            • 4. Re: Flex with JSP
              Sankar Kethineni
              Hi JB2622,

              As u said i tried but it's not working. If you won't give entire location of the file how the compiler will know?
              • 5. Re: Flex with JSP
                JimBrychka Level 1
                sankar83

                Maybe we are not talking about the same thing. The jsp page that I'm referring to is included with my Flex application. The following syntax works when I call the jsp page from this Flex application:

                navigateToURL(new URLRequest("/DataExportExample/jsp/downloadCSV.jsp"), "_blank");

                The "DataExportExample" is the context root of the application. I have also called a jsp without the context root:
                navigateToURL(new URLRequest("jsp/downloadCSV.jsp"), "_blank");

                • 6. Re: Flex with JSP
                  Sankar Kethineni Level 1
                  Hi JB2622,

                  Ok, right now am comfortable with your eariler suggestion and i will try with navigateToURL later since am new to flex and i have one more problem and i think you will solve this problem

                  here is the scenario , am trying to connect to the my-sql database and get the data from the DB in the JSP page ( employee.jsp) and trying to displaying those records through the MXML using the DataGrid as shown in the following code

                  I have deployed that employee.jsp in the Tomcat Server and am able to display those recoeds( http://localhost:8080/employee.jsp in the browser), but the problem is am not able to display those records through the MXML.


                  sample.mxml

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
                  initialize="emp.send()">

                  <!--<mx:Script>
                  <![CDATA[
                  private function onResult(event:Event):void
                  {
                  return;
                  }
                  ]]>
                  </mx:Script>-->

                  <mx:HTTPService id="emp" method="POST" url=" http://localhost:8080/employee.jsp"/>

                  <mx:DataGrid dataProvider="{emp.lastResult.employees.employee}" x="100" y="100">
                  <mx:columns>
                  <mx:DataGridColumn dataField="firstname" headerText="First Name"/>
                  <mx:DataGridColumn dataField="lastname" headerText="Last Name"/>
                  <mx:DataGridColumn dataField="age" headerText="Age"/>
                  <mx:DataGridColumn dataField="designation" headerText="Designation"/>
                  </mx:columns>
                  </mx:DataGrid>

                  </mx:Application>


                  employee.jsp


                  <%@ page language="java" contentType="text/html; charset=UTF-8"
                  pageEncoding="UTF-8"%>
                  <%@ page import="java.sql.*" %>
                  <employees>
                  <%
                  try
                  {
                  Class.forName("com.mysql.jdbc.Driver");
                  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sankar","root","sankar");
                  out.println("Successfully connected to my-sql <br>");

                  Statement stmt=con.createStatement();
                  ResultSet rs=stmt.executeQuery("select * from employee");
                  while(rs.next())
                  {
                  %>

                  <employee>
                  <firstname><%= rs.getString(1) %></firstname>
                  <lastname><%= rs.getString(2) %></lastname>
                  <age><%= rs.getString(3) %></age>
                  <designation><%= rs.getString(4) %></designation>
                  </employee>

                  <% }

                  con.close();

                  }
                  catch(Exception e)
                  {
                  System.out.println("Exception due to:"+e);
                  }
                  %>
                  </employees>

                  • 7. Flex with JSP
                    Sankar Kethineni Level 1
                    Hi JB2622,

                    myself find the solution for the database problem.The change is simple thing only that is change the

                    contentType="text/html" to contentType="text/xml" in the employee.jsp

                    then it will work fine.
                    • 8. Re: Flex with JSP
                      ac361 Level 1
                      You can also use a servlet with your Flex app, though setting the paths up in your web.xml can be tricky. I just finished doing that for a project. Here's one example of a servlet for a Flex app: http://blog.kevinhoyt.org/2007/12/07/flex-to-java-servlet-file-upload/

                      If you look further down that linked page, you'll see a link to the source code.