在 myeclipse 中配置Flex + Spring + Hiberate + Struts

在 myeclipse 中配置Flex + Spring + Hiberate + Struts 

1. web.xml 的配置 

   <web-app> 
<display-name>FLEX_J2EEDEMO</display-name> 
<description> 
Administration tools for monitoring and management 
</description> 
<context-param> 
<param-name>flex.class.path</param-name> 
<param-value> 
/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars 
</param-value> 
</context-param> 
<!-- Http Flex Session attribute and binding listener support --> 
<listener> 
<listener-class>flex.messaging.HttpFlexSession</listener-class> 
</listener> 
<!-- MessageBroker Servlet --> 
<servlet> 
<servlet-name>MessageBrokerServlet</servlet-name> 
<display-name>MessageBrokerServlet</display-name> 
<servlet-class> 
flex.messaging.MessageBrokerServlet 
</servlet-class> 
<init-param> 
<param-name>services.configuration.file</param-name> 
<param-value>/WEB-INF/flex/services-config.xml</param-value> 
</init-param> 
<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet> 
<servlet-name>action</servlet-name> 
<servlet-class> 
org.apache.struts.action.ActionServlet 
</servlet-class> 
<init-param> 
<param-name>config</param-name> 
<param-value>/WEB-INF/struts-config.xml</param-value> 
</init-param> 
<init-param> 
<param-name>debug</param-name> 
<param-value>3</param-value> 
</init-param> 
<init-param> 
<param-name>detail</param-name> 
<param-value>3</param-value> 
</init-param> 
<load-on-startup>0</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>MessageBrokerServlet</servlet-name> 
<url-pattern>/messagebroker/*</url-pattern> 
</servlet-mapping> 
<!-- 添加spring --> 
<servlet> 
<servlet-name>SpringContextServlet</servlet-name> 
<servlet-class> 
org.springframework.web.context.ContextLoaderServlet 
</servlet-class> 
<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>action</servlet-name> 
<url-pattern>*.do</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
</welcome-file-list> 
<!-- for WebSphere deployment, please uncomment --> 
<!-- 
<resource-ref> 
<description>Flex Messaging WorkManager</description> 
<res-ref-name>wm/MessagingWorkManager</res-ref-name> 
<res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type> 
<res-auth>Container</res-auth> 
<res-sharing-scope>Shareable</res-sharing-scope> 
</resource-ref> 
--> 
</web-app> 

2. Spring , Hiberate , Struts 的配置参加一般J2EE 配置 

3. 配置flex 

   项目WEB-INF下建立flex文件夹,放置services-config.xml,remoting-config.xml。 
   
    services-config.xml 内容如下:  
    <?xml version="1.0" encoding="UTF-8"?> 
<services-config> 

    <services> 
       <service-include file-path="remoting-config.xml" /> 
    </services> 
    
      <factories> 
<factory id="spring" class="flex.samples.factories.SpringFactory"/> 
</factories> 
   
        <security> 
            <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>        
            <!-- Uncomment the correct app server 
            <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss"> 
            <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>       
            <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/> 
            <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/> 
            --> 
        
        <!--  
        If running the console on WebSphere with administrative security enabled uncomment this section.  Also, 
        create a User Group called "console_administrator" and add any users that are allowed to use the console to this group. 
        These users must also have at least one role that allows them to access MBeans under WebSphere security.  Finally, 
        be sure to use the WebSphere login-command above.  
        <security-constraint id="console"> 
            <auth-method>Basic</auth-method> 
            <roles> 
                <role>console_administrator</role> 
               </roles> 
           </security-constraint> 
           -->        
        </security> 


    <channels> 

        <channel-definition id="amf" class="mx.messaging.channels.AMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/> 
            <properties> 
                <polling-enabled>false</polling-enabled> 
            </properties> 
        </channel-definition> 

    </channels> 

    <logging> 

        <!-- You may also use flex.messaging.log.ServletLogTarget --> 
        <target class="flex.messaging.log.ConsoleTarget" level="Error"> 
            <properties> 
                <prefix>[BlazeDS] </prefix> 
                <includeDate>false</includeDate> 
                <includeTime>false</includeTime> 
                <includeLevel>true</includeLevel> 
                <includeCategory>true</includeCategory> 
            </properties> 
            <filters> 
                <pattern>Endpoint.*</pattern> 
            </filters> 
        </target> 

    </logging> 

    <system> 
        <redeploy> 
            <enabled>true</enabled> 
            <watch-interval>20</watch-interval> 
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file> 
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file> 
        </redeploy> 
    </system> 

</services-config> 

     remoting-config.xml内容如下 

<?xml version="1.0" encoding="UTF-8"?> 
<service id="remoting-service" 
    class="flex.messaging.services.RemotingService" 
    messageTypes="flex.messaging.messages.RemotingMessage"> 

    <adapters> 
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> 
    </adapters> 

    <default-channels> 
        <channel ref="amf"/> 
    </default-channels> 
    
    <!-- 定义名为userService的服务 ,从spring容器中获得--> 
   <destination id="userService"> 

     <properties> 
          <factory>spring</factory> 
          <source>userService</source> 
     </properties> 

   </destination> 

</service> 


通过以上配置文件,可在.mxml中直接应用J2ee 中的 userService 
如FLEX_LOGIN.mxml中登录应用,内容如下 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:rpc="com.adobe.fxstruts.rpc.*" layout="absolute" > 
<mx:Script> 
        <![CDATA[                
            import flash.events.Event; 
            import mx.controls.Alert; 
            import mx.utils.ArrayUtil; 
            import mx.rpc.events.ResultEvent; 
            import mx.controls.Alert; 
            private var userObj:Object=new Object(); 
            public var userName:String=""; 

            private function reset():void{ 
               username.text=""; 
               password.text=""; 
            } 
            
            private function sendKeyHandler(evt:KeyboardEvent):void 
            { 

            //Enter 键 
                if (evt.keyCode == 13) 
            { 
               this.login(); 
               return ; 
                   } 
            } 

            private function loginResult(result:Object):void 
            { 
            userObj=Object(result); 
            if(userObj["userPwd"]==password.text){ 
               Alert.show(userObj["fullName"]+"登录成功!"); 
                   }else 
            { 
               Alert.show(username.text+"登录失败!"); 
            }       
            } 
            
            private function login():void{ 
          
            if(username.text=="" || password.text=="" ){ 
            Alert.show("请输入用户名或密码!"); 
            }else{ 
                userObj = getData.getUserByCode(username.text); 
                userName=username.text; 
            } 
            } 
                          
      ]]> 
    </mx:Script> 
     
    <mx:Panel  
        height="75%" width="75%" layout="absolute" 
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"> 
    <mx:Label width="71" color="blue" text="用户名" fontSize="14" x="41" y="36"/> 
    <mx:TextInput  width="148" height="20" id="username" maxChars="20" editable="true" cornerRadius="1" x="97" y="38"/> 
    <mx:Label width="37" color="blue" text="密码" fontSize="14" x="41" y="76"/> 
    <mx:TextInput  editable="true" width="148" height="20" id="password" cornerRadius="1" displayAsPassword="true" enabled="true" maxChars="20" x="97" y="78"  keyDown="sendKeyHandler(event)"/>
    <mx:Button label="登录" width="67" fontSize="12" x="58" y="118"  click="login()"/> 
    <mx:Button label="取消" width="68" fontSize="12" x="154" y="118" click="reset()"/> 
    </mx:Panel> 
    <mx:RemoteObject id="getData" destination="userService"> 
<mx:method name="getUserByCode" result="loginResult(event.result)" fault="Alert.show(event.fault.faultString,'Error')"/> 
    </mx:RemoteObject> 
</mx:Application> 




    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用MyEclipse进行Spring Struts2 Hibernate开发过程,可以按照以下步骤进行前后台的添加。 首先,对于后台开发,需要配置Hibernate的相关环境。可以在MyEclipse创建一个新的Java项目,然后在项目添加相关的Hibernate库文件,包括Hibernate的核心库、连接池库和数据库驱动库。接着,在项目创建一个Hibernate配置文件,配置数据库连接等相关信息。然后,创建实体类对应数据库表的字段,并使用注解或XML文件进行映射。接下来,在DAO层创建与数据库交互的方法,并使用Hibernate相关API进行数据库操作。 对于前台开发,可以使用Spring MVC和Struts2来进行。首先,需要在项目添加相关的SpringStruts2的库文件。然后,在Spring配置文件(如applicationContext.xml)配置Spring MVC的相关信息,如视图解析器、控制器等。接着,在项目创建Controller类,使用注解或XML文件进行映射URL与方法的关系,并在方法实现相应的业务逻辑。同时,可以创建对应的JSP页面,用于展示数据或与用户交互。 在整个开发过程,可以使用MyEclipse提供的快速开发工具来简化代码编写和调试,如自动生成实体类、自动生成Controller类等。此外,MyEclipse还提供了集成的调试工具,可以方便地进行代码调试和错误排查。 总结起来,使用MyEclipse进行Spring Struts2 Hibernate开发的前后台教学,需要进行环境配置、实体类的定义与映射、配置文件的编写、业务逻辑的实现以及页面的设计与交互等步骤。通过合理利用MyEclipse的功能,可以提高开发效率和代码质量,实现前后台数据的交互和展示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值