<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 241,  comments - 116,  trackbacks - 0
    1. 復制jar到WEB-INF/lib目錄:
      復制,并添加到java build path:
      Sql代碼  收藏代碼
      1. org.springframework.aop-3.1.0.M1.jar  
      2. org.springframework.asm-3.1.0.M1.jar  
      3. org.springframework.beans-3.1.0.M1.jar  
      4. org.springframework.context-3.1.0.M1.jar  
      5. org.springframework.core-3.1.0.M1.jar  
      6. org.springframework.expression-3.1.0.M1.jar  
      7. org.springframework.web-3.1.0.M1.jar  
       
      spring包分類總結:
      Sql代碼  收藏代碼
      1. ============================================  
      2. spring3 lib:  
      3.     core:  
      4.         org.springframework.beans-3.0.5.RELEASE.jar  
      5.         org.springframework.core-3.0.5.RELEASE.jar  
      6.         org.springframework.context-3.0.5.RELEASE.jar  
      7.         org.springframework.expression-3.0.5.RELEASE.jar  
      8.         core depend lib:  
      9.             org.springframework.asm-3.0.5.RELEASE.jar  
      10.     web:  
      11.         tld: spring.tld, spring-form.tld  
      12.         org.springframework.web-3.0.5.RELEASE.jar  
      13.         springMVC: org.springframework.web.servlet-3.0.5.RELEASE.jar  
      14.     db:  
      15.         org.springframework.orm-3.0.2.RELEASE.jar  
      16.         org.springframework.transaction-3.0.2.RELEASE.jar  
      17.         org.springframework.jdbc-3.0.2.RELEASE.jar  
      18.     aop:  
      19.         org.springframework.aop-3.0.5.RELEASE.jar  
      20.         depend on:  
      21.             aopalliance-1.0.jar  
      22. ============================================  
       
    2. 配置applicationContext.xml,并配置LoginAction的bean
      1. 普通bean配置,注意加上scope="prototype"
      2. 注解方式配置:<context:component-scan base-package="org.skzr.demo"/>
        applicationContext.xml:
        Xml代碼  收藏代碼
        1. <?xml version="1.0" encoding="UTF-8"?>  
        2. <beans xmlns="http://www.springframework.org/schema/beans"  
        3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"  
        4.     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"  
        5.     xsi:schemaLocation="  
        6.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
        7.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
        8.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
        9.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
        10.   
        11.     <bean id="loginAction" class="org.skzr.demo.action.LoginAction" scope="prototype"/>  
        12.       
        13.     <context:component-scan base-package="org.skzr.demo"/>  
        14. </beans>  
         添加注解到LoginAction.java,注意:@Component("loginActionComponent") @Scope("prototype")
        Java代碼  收藏代碼
        1. /** 
        2.  * Copyright (c) 2010-2020 by wasion.com 
        3.  * All rights reserved. 
        4.  * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a> 
        5.  * @date 2011-5-19 下午10:20:57 
        6.  */  
        7. package org.skzr.demo.action;  
        8.   
        9. import org.springframework.context.annotation.Scope;  
        10. import org.springframework.stereotype.Component;  
        11.   
        12. import com.opensymphony.xwork2.ActionSupport;  
        13.   
        14. /** 
        15.  * 登錄檢測 
        16.  * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a> 
        17.  * @version 1.0.0 
        18.  * @since JDK1.6 
        19.  */  
        20. @Component("loginActionComponent")  
        21. @Scope("prototype")  
        22. public class LoginAction extends ActionSupport {  
        23.     private static final long serialVersionUID = 1L;  
        24.     /** 用戶名 */  
        25.     private String userName;  
        26.     /** 密碼 */  
        27.     private String password;  
        28.       
        29.     /** 
        30.      * @return {@link #userName} 
        31.      */  
        32.     public String getUserName() {  
        33.         return userName;  
        34.     }  
        35.     /** 
        36.      * @param userName {@link #userName} 
        37.      */  
        38.     public void setUserName(String userName) {  
        39.         this.userName = userName;  
        40.     }  
        41.     /** 
        42.      * @return {@link #password} 
        43.      */  
        44.     public String getPassword() {  
        45.         return password;  
        46.     }  
        47.     /** 
        48.      * @param password {@link #password} 
        49.      */  
        50.     public void setPassword(String password) {  
        51.         this.password = password;  
        52.     }  
        53.   
        54.     /** 
        55.      * 登錄驗證 
        56.      * @return 驗證后頁面視圖 
        57.      */  
        58.     public String check() {  
        59.         return "admin".equals(userName) ? "welcome" : "success";  
        60.     }  
        61. }  
         
    3. 修改web.xml
      Xml代碼  收藏代碼
      1. <?xml version="1.0" encoding="UTF-8"?>  
      2. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"  
      3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
      5.     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  
      6.     <description>我愛編程</description>  
      7.     <display-name>我愛編程</display-name>  
      8.       
      9.     <context-param>  
      10.         <param-name>webAppRootKey</param-name>  
      11.         <param-value>app.root</param-value>  
      12.     </context-param>  
      13.     <context-param>  
      14.         <param-name>log4jRefreshInterval</param-name>  
      15.         <param-value>10000</param-value>  
      16.     </context-param>  
      17.       
      18.     <context-param>  
      19.         <param-name>contextConfigLocation</param-name>  
      20.         <param-value>  
      21.             classpath*:applicationContext.xml  
      22.         </param-value>  
      23.     </context-param>  
      24.     <listener>  
      25.         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
      26.     </listener>  
      27.     <listener>  
      28.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
      29.     </listener>  
      30.       
      31.     <filter>  
      32.         <filter-name>struts2</filter-name>  
      33.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
      34.         <init-param>  
      35.             <param-name>config</param-name>  
      36.             <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>  
      37.         </init-param>  
      38.     </filter>  
      39.     <filter-mapping>  
      40.         <filter-name>struts2</filter-name>  
      41.         <url-pattern>*.do</url-pattern>  
      42.     </filter-mapping>  
      43.       
      44.     <welcome-file-list>  
      45.         <welcome-file>index.jsp</welcome-file>  
      46.     </welcome-file-list>  
      47. </web-app>  
       
    4. 啟動web查看后臺輸出是不是正常初始化spring
    5. 修改struts.xml的action從spring中獲取
      Xml代碼  收藏代碼
      1. <?xml version="1.0" encoding="UTF-8" ?>  
      2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
      3. <struts>  
      4.     <package name="demo" extends="struts-default" namespace="/">  
      5.         <action name="loginAction" class="org.skzr.demo.action.LoginAction">  
      6.             <result>/WEB-INF/jsp/login.jsp</result>  
      7.             <result name="welcome">/WEB-INF/jsp/welcome.jsp</result>  
      8.         </action>  
      9.         <!-- 來自spring配置的bean -->  
      10.         <action name="loginActionSpring" class="loginAction">  
      11.             <result>/WEB-INF/jsp/login.jsp</result>  
      12.             <result name="welcome">/WEB-INF/jsp/welcome.jsp</result>  
      13.         </action>  
      14.         <!-- 來自spring注解配置的bean -->  
      15.         <action name="loginActionSpringComponent" class="loginActionComponent">  
      16.             <result>/WEB-INF/jsp/login.jsp</result>  
      17.             <result name="welcome">/WEB-INF/jsp/welcome.jsp</result>  
      18.         </action>  
      19.     </package>  
      20. </struts>      
       
    6. 哈哈struts運行不正常了,無法使用spring的:
      1. 修改struts.properties添加spring支持:struts.objectFactory=spring
      2. 復制struts2-spring-plugin-2.2.3.jar到lib,并添加到java build path
      3. 重新運行系統即可正常登錄了。
        新的登錄頁面login.jsp
        Html代碼  收藏代碼
        1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
        2. <%  
        3. String path = request.getContextPath();  
        4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
        5. %>  
        6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
        7. <html>  
        8.     <head>  
        9.         <base href="<%=basePath%>">  
        10.         <title>系統登錄:</title>  
        11.         <meta http-equiv="pragma" content="no-cache">  
        12.         <meta http-equiv="cache-control" content="no-cache">  
        13.         <meta http-equiv="expires" content="0">  
        14.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
        15.         <meta http-equiv="description" content="This is my page">  
        16.     </head>  
        17.   
        18.     <body>  
        19.         <center><h1>struts action</h1></center>  
        20.         <form action="loginAction!check.do" method="post">  
        21.             <table align="center">  
        22.                     <tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>  
        23.                     <tr><td>密&nbsp;碼:</td><td><input name="password" type="password"></td></tr>  
        24.                     <tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>  
        25.             </table>  
        26.         </form>  
        27.           
        28.         <center><h1>action配置在spring中的</h1></center>  
        29.         <form action="loginActionSpring!check.do" method="post">  
        30.             <table align="center">  
        31.                     <tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>  
        32.                     <tr><td>密&nbsp;碼:</td><td><input name="password" type="password"></td></tr>  
        33.                     <tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>  
        34.             </table>  
        35.         </form>  
        36.           
        37.         <center><h1>action配置在spring中的(注解方式配置)</h1></center>  
        38.         <form action="loginActionSpringComponent!check.do" method="post">  
        39.             <table align="center">  
        40.                     <tr><td>用戶名:</td><td><input name="userName" value="${userName }"></td></tr>  
        41.                     <tr><td>密&nbsp;碼:</td><td><input name="password" type="password"></td></tr>  
        42.                     <tr><td><input type="submit" value="登錄"></td><td><input type="reset" value="重置"></td></tr>  
        43.             </table>  
        44.         </form>  
        45.     </body>  
        46. </html>  
         
    posted on 2011-05-20 14:58 墻頭草 閱讀(822) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    人人游戲網 軟件開發網 貨運專家
    主站蜘蛛池模板: 欧美男同gv免费网站观看| 国产一卡2卡3卡4卡2021免费观看| 国产无遮挡又黄又爽免费视频| 亚洲免费电影网站| 日韩国产免费一区二区三区| 国产精品亚洲精品青青青| 成全视频免费高清 | 亚洲AV日韩AV天堂久久 | 色欲A∨无码蜜臀AV免费播 | 亚洲精品无码国产| 你是我的城池营垒免费看 | 国产亚洲婷婷香蕉久久精品| av永久免费网站在线观看| 亚洲AV无码国产丝袜在线观看| 久章草在线精品视频免费观看| 亚洲精品无码久久毛片波多野吉衣| 亚欧人成精品免费观看| 亚洲第一区二区快射影院| 成人永久免费福利视频网站| 免费的黄网站男人的天堂| 国产精品久久久亚洲| 99无码人妻一区二区三区免费| 亚洲精品无码人妻无码| 亚洲精品在线视频| 99re在线这里只有精品免费| 亚洲一区电影在线观看| 亚洲国产中文字幕在线观看| 华人在线精品免费观看| 丁香婷婷亚洲六月综合色| 亚洲AV永久无码精品一区二区国产| 99麻豆久久久国产精品免费 | 成人毛片免费视频| 一个人看的www视频免费在线观看| 亚洲AV无码乱码在线观看富二代 | 亚洲欧洲高清有无| 亚洲av再在线观看| 亚洲第一网站免费视频| 美女尿口扒开图片免费 | 亚洲不卡中文字幕无码| 免费三级毛片电影片| 一区在线免费观看|