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

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

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

    常用鏈接

    統計

    最新評論

    2011年2月13日 #

    Create Struts 2 Application in Eclipse : HTTP Status 500

    http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html 

    problem:

    HTTP Status 500 

    java.lang.NullPointerException 	
    org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    resolve problem:
    1. struts.xml should under src
    2. in struts.xml:  
    <action name="login" method="excute"
    class="net.viralpatel.struts2.LoginAction">

    posted @ 2012-04-21 02:41 九寶 閱讀(399) | 評論 (0)編輯 收藏

    How to check file properties through WMI command line (fw)

    How to check file properties through WMI command line

    24.Sep.2009 | by Gusac | Filed in: Articles, Tutorials

    With the lack of Graphical Interface on Windows 2008 Core server there comes a need of performing a lot of task through command line. One of which is checking file properties like file version, path, product verision etc. Luckily we have a command that makes this task simple. On a side note, We can also run the same command on other operating systems like Windows Xp, 2003, vista.

    Here is the command:
    wmic datafile where name='c:\\windows\\system32\\notepad.exe'

    Click here to view the enlarged screenshot

    Notice that we have used two backslashes \\ in the file path. Also, notice that the path is enclosed in the single quotes.
    The output will be confusing to read in command prompt window. To read and understand it better, we can take the output in text format and read it in notepad.

    While doing so, please do NOT wrap the text.
    wmic datafile where name='c:\\windows\\system32\\notepad.exe' > out.txt

    Click here to view the enlarged screenshot

    The output will reveal the file properties like Hidden, Path, Drive, Version Caption, Access rights etc.

    To get one particular property of a file we need to modify the command a little bit. We need to use the GET Alias injunction to the command mentioned above. Let's say we want to check the version for the file notepad.exe. The command that is used for this is:
    wmic datafile where name='c:\\windows\\system32\\notepad.exe' get version

    Similarily, there is a list of properties that can be fetched through this command line. They are:

    Access Rights
    Caption
    Class Name
    Compressed
    Compression Method
    Computer System Class Name
    Computer System Name
    Creation Date
    Current File Open Count
    Description
    Drive
    Eight Dot Three File Name
    Encrypted
    Encryption Method
    File Extension
    File Name
    File System Class Name
    File System Name
    File Type
    Hidden
    Install Date
    Last Accessed
    Last Modified
    Manufacturer
    Name
    Path
    Readable
    Should Be Archived
    Size
    Status
    System File
    Version
    Writeable

    posted @ 2011-12-07 22:29 九寶 閱讀(360) | 評論 (0)編輯 收藏

    Windows Authentication

    from http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication

    Overview

    The <windowsAuthentication> element defines configuration settings for the Internet Information Services (IIS) 7 Windows authentication module. You can use Windows authentication when your IIS 7 server runs on a corporate network that is using Microsoft Active Directory service domain identities or other Windows accounts to identify users. Because of this, you can use Windows authentication whether or not your server is a member of an Active Directory domain.

    Windows authentication (formerly named NTLM, and also referred to as Windows NT Challenge/Response authentication) is a secure form of authentication because the user name and password are hashed before being sent across the network. When you enable Windows authentication, the client browser sends a strongly hashed version of the password in a cryptographic exchange with your Web server.

    Windows authentication supports two authentication protocols, Kerberos and NTLM, which are defined in the <providers> element. When you install and enable Windows authentication on IIS 7, the default protocol is Kerberos. The <windowsAuthentication> element can also contain a useKernelMode attribute that configures whether to use the kernel mode authentication feature that is new to Windows Server 2008.

    Windows authentication is best suited for an intranet environment for the following reasons:

    • Client computers and Web servers are in the same domain.
    • Administrators can make sure that every client browser is Internet Explorer 2.0 or later.
    • HTTP proxy connections, which are not supported by NTLM, are not required.
    • Kerberos version 5 requires a connection to Active Directory, which is not feasible in an Internet environment.

    New in IIS 7.5

    The <extendedProtection> element was introduced in IIS 7.5, which allows you to configure the settings for the new extended protection features that have been integrated into Windows authentication.

    Compatibility

    Version Notes
    IIS 7.5 The <extendedProtection> element was added in IIS 7.5.
    IIS 7.0 The <windowsAuthentication> element was introduced in IIS 7.0.
    IIS 6.0 The <windowsAuthentication> element replaces portions of the IIS 6.0 AuthType and AuthFlags metabase properties.

    Setup

    The default installation of IIS 7 does not include the Windows authentication role service. To use Windows authentication on IIS, you must install the role service, disable Anonymous authentication for your Web site or application, and then enable Windows authentication for the site or application.

    Note: After you install the role service, IIS 7 commits the following configuration settings to the ApplicationHost.config file.

    <windowsAuthentication enabled="false" />

    Windows Server 2008 or Windows Server 2008 R2

    1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
    2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
    3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
    4. On the Select Role Services page of the Add Role Services Wizard, select Windows Authentication, and then click Next.
    5. On the Confirm Installation Selections page, click Install.
    6. On the Results page, click Close.

    Windows Vista or Windows 7

    1. On the taskbar, click Start, and then click Control Panel.
    2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
    3. Expand Internet Information Services, then World Wide Web Services, then Security.
    4. Select Windows Authentication, and then click OK.

    How To

    How to enable Windows authentication for a Web site, Web application, or Web service

    1. Open Internet Information Services (IIS) Manager:
      • If you are using Windows Server 2008 or Windows Server 2008 R2:
        • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
      • If you are using Windows Vista or Windows 7:
        • On the taskbar, click Start, and then click Control Panel.
        • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    2. In the Connections pane, expand the server name, expand Sites, and then the site, application, or Web service for which you want to enable Windows authentication.
    3. Scroll to the Security section in the Home pane, and then double-click Authentication.
    4. In the Authentication pane, select Windows Authentication, and then click Enable in the Actions pane.

    How to enable Extended Protection for Windows authentication

    1. Open Internet Information Services (IIS) Manager:
      • If you are using Windows Server 2008 or Windows Server 2008 R2:
        • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
      • If you are using Windows Vista or Windows 7:
        • On the taskbar, click Start, and then click Control Panel.
        • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    2. In the Connections pane, expand the server name, expand Sites, and then the site, application, or Web service for which you want to enable Extended Protection for Windows authentication.
    3. Scroll to the Security section in the Home pane, and then double-click Authentication.
    4. In the Authentication pane, select Windows Authentication.
    5. Click Enable in the Actions pane.
    6. Click Advanced Settings in the Actions pane.
    7. When the Advanced Settings dialog box appears, select one of the following options in the Extended Protection drop-down menu:
      • Select Accept if you want to enable extended protection while providing down-level support for clients that do not support extended protection.
      • Select Required if you want to enable extended protection without providing down-level support.
    8. Click OK to close the Advanced Settings dialog box.

    Configuration

    The <windowsAuthentication> element is configurable at the site, application, or virtual directory level in the ApplicationHost.config file.

    Attributes

    Attribute Description
    authPersistNonNTLM Optional Boolean attribute.

    Specifies whether IIS automatically reauthenticates every non-NTLM (for example, Kerberos) request, even those on the same connection. False enables multiple authentications for the same connections.

    Note: A setting of true means that the client will be authenticated only once on the same connection. IIS will cache a token or ticket on the server for a TCP session that stays established.

    The default is false.
    authPersistSingleRequest Optional Boolean attribute.

    Setting this flag to true specifies that authentication persists only for a single request on a connection. IIS resets the authentication at the end of each request, and forces reauthentication on the next request of the session.

    The default value is false.
    enabled Required Boolean attribute.

    Specifies whether Windows authentication is enabled.

    The default value is false.
    useKernelMode Optional Boolean attribute.

    Specifies whether Windows authentication is done in kernel mode. True specifies that Windows authentication uses kernel mode.

    Kernel-mode authentication may improve authentication performance and prevent authentication problems with application pools that are configured to use a custom identity.

    As a best practice, do not disable this setting if you use Kerberos authentication and have a custom identity on the application pool.

    The default is true.

    Child Elements

    Element Description
    extendedProtection Optional element.

    Specifies extended protection options for Windows authentication.

    Note: This element was added in IIS 7.5.
    providers Optional element.

    Specifies security support providers used for Windows authentication.

    Configuration Sample

    The following default <windowsAuthentication> element is configured at the root ApplicationHost.config file in IIS 7.0, and disables Windows authentication by default. It also defines the two Windows authentication providers for IIS 7.0.

    <windowsAuthentication enabled="false">
       <providers>
          <add value="Negotiate" />
          <add value="NTLM" />
       </providers>
    </windowsAuthentication>

    The following example enables Windows authentication and disables Anonymous authentication for a Web site named Contoso.

    <location path="Contoso">
       <system.webServer>
          <security>
             <authentication>
                <anonymousAuthentication enabled="false" />
                <windowsAuthentication enabled="true" />
             </authentication>
          </security>
       </system.webServer>
    </location>

    Sample Code

    The following examples disable Anonymous authentication for a site named Contoso, then enable Windows authentication for the site.

    AppCmd.exe

    appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False" /commit:apphost
    
    appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost

    Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

    C#

    using System;
    using System.Text;
    using Microsoft.Web.Administration;
    
    internal static class Sample {
    
       private static void Main() {
    
          using(ServerManager serverManager = new ServerManager()) { 
             Configuration config = serverManager.GetApplicationHostConfiguration();
    
             ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
             anonymousAuthenticationSection["enabled"] = false;
    
             ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
             windowsAuthenticationSection["enabled"] = true;
    
             serverManager.CommitChanges();
          }
       }
    }

    VB.NET

    Imports System
    Imports System.Text
    Imports Microsoft.Web.Administration
    
    Module Sample
       Sub Main()
          Dim serverManager As ServerManager = New ServerManager
          Dim config As Configuration = serverManager.GetApplicationHostConfiguration
    
          Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
          anonymousAuthenticationSection("enabled") = False
    
          Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso")
          windowsAuthenticationSection("enabled") = True
    
          serverManager.CommitChanges()
       End Sub
    End Module

    JavaScript

    var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
    adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
    
    var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
    anonymousAuthenticationSection.Properties.Item("enabled").Value = false;
    
    var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
    windowsAuthenticationSection.Properties.Item("enabled").Value = true;
    
    adminManager.CommitChanges();

    VBScript

    Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
    adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
    
    Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
    anonymousAuthenticationSection.Properties.Item("enabled").Value = False
    
    Set windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
    windowsAuthenticationSection.Properties.Item("enabled").Value = True
    
    adminManager.CommitChanges()

    posted @ 2011-09-16 21:46 九寶 閱讀(645) | 評論 (0)編輯 收藏

    How To Determine if Your Computer Is 32-Bit or 64-Bit(forward)

    how to check window version

    run: Winver


    Here's How:
    1. Open the System Information

      Open the Start menu, and click on Programs -> Accessories -> System Tools -> System Information

       

    2. Look in the System Summary

      The System Information tool will display detailed information about your Windows operating system. Once opened it will show the "System Summary" – it’s an overview of your computer and operating system.

    3. Look for the System Type Item

      On the right hand side of the window you will see a list of items. Look for the item called "System Type".

      The value of this item will tell you whether your computer is 32-bit or 64-bit:

      • x86-based PC: It’s a 32-bit computer.
      • x64-based PC: It’s a 64-bit computer.

       

    posted @ 2011-09-16 03:34 九寶 閱讀(255) | 評論 (0)編輯 收藏

    ContentProvider分析

         摘要: ContentProvider何時創建呢?這是一個值得深思的問題?  據我這兩天的了解是在你要用到的時候才會調用ContentProvider的onCreate函數進行創建。你就會什么時候叫要用到的時候呢?比如你要查詢或刪除修改數據庫的時候通過ContentResolver的quire或delete來操縱數據時就會調用ContentProvider的onCreate函數,若已經創建了數...  閱讀全文

    posted @ 2011-02-18 14:51 九寶 閱讀(1862) | 評論 (0)編輯 收藏

    GestureDetector手勢識別類 (轉)

    View是在onTouchEvent(MotionEvent event)里對用戶的動作做了一定的分析,從而通知我們是發生了點擊還是長按等事件。

    我們需要創建一個GestureDetector的對象,傳入listener對象,view接收到的onTouchEvent中將event傳給GestureDetector進行分析listener會回調給我們相應的動作。其中GestureDetector.SimpleOnGestureListenerFramework幫我們簡化了)是實現了上面提到的OnGestureListenerOnDoubleTapListener兩個接口的類,我們只需要繼承它并重寫其中我們關心的回調即可。

    ,那么,這個類如何使用呢?以下是使用該類的一個范例:

    private GestureDetector mGestureDetector;

    @Override

    public void onCreate(Bundle savedInstanceState) {


      super.onCreate(savedInstanceState);


      mGestureDetector = new GestureDetector(this, new MyGestureListener());


    }


    @Override

    public boolean onTouchEvent(MotionEvent event) {

     return mGestureDetector.onTouchEvent(event); 

    /*  有關上面的 onTouchEvent方法,我們可以直接判斷MotionEvent的類型,

        對于手勢移動僅僅捕獲ACTION_MOVE即可,

        我們通過參數MotionEvent e1, MotionEvent e2,float distanceX, float distanceY可以獲取操作變化。

       比如 distanceX > 0 向右邊移動,distanceX < 0 則向左邊,distanceY > 0 向上滾動, distanceY < 0 向下滾動。

    */

    }


    class MyGestureListener extends GestureDetector.SimpleOnGestureListener{

      @Override

      public boolean onSingleTapUp(MotionEvent ev) {

        Log.d("onSingleTapUp",ev.toString());

        return true;

      }


      @Override

      public void onShowPress(MotionEvent ev) {

        Log.d("onShowPress",ev.toString());

      }


      @Override

      public void onLongPress(MotionEvent ev) {

        Log.d("onLongPress",ev.toString());

      }

    }

     


    更多的回調消息,方便的對用戶的動作進行響應

    public interface OnGestureListener {

                    // Touch down時觸發, edown時的MotionEvent

                    boolean onDown(MotionEvent e);

                    // Touch down之后一定時間(115ms)觸發,edown時的MotionEvent

                    void onShowPress(MotionEvent e);

                    // Touch up時觸發,eup時的MotionEvent

                    boolean onSingleTapUp(MotionEvent e);

                    // 滑動時觸發,e1down時的MotionEvente2move時的MotionEvent

                    boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY);

                    // Touch down之后一定時間(500ms)觸發,edown時的MotionEvent

                    void onLongPress(MotionEvent e);

                    // 滑動一段距離,up時觸發,e1down時的MotionEvente2up時的MotionEvent

                    boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);

    } 

    public interface OnDoubleTapListener {

                    // 完成一次單擊,并確定沒有二擊事件后觸發(300ms),edown時的MotionEvent

                    boolean onSingleTapConfirmed(MotionEvent e);

                    // 第二次單擊down時觸發,e為第一次down時的MotionEvent

                    boolean onDoubleTap(MotionEvent e);

                    // 第二次單擊down,moveup時都觸發,e為不同時機下的MotionEvent

                    boolean onDoubleTapEvent(MotionEvent e);

    }

    boolean  onDoubleTap(MotionEvent e)
    解釋:雙擊的第二下Touch down時觸發
    boolean  onDoubleTapEvent(MotionEvent e)
    解釋:雙擊的第二下Touch down和up都會觸發,可用e.getAction()區分。
    boolean  onDown(MotionEvent e)
    解釋:Touch down時觸發
    boolean  onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    解釋:Touch了滑動一點距離后,up時觸發。
    void  onLongPress(MotionEvent e)
    解釋:Touch了不移動一直Touch down時觸發
    boolean  onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    解釋:Touch了滑動時觸發。
    void  onShowPress(MotionEvent e)
    解釋:Touch了還沒有滑動時觸發
    (與onDown,onLongPress比較,onDown只要Touch down一定立刻觸發。而Touchdown后過一會沒有滑動先觸發onShowPress再是onLongPress。
    所以Touchdown后一直不滑動,onDown->onShowPress->onLongPress這個順序觸發。
    boolean  onSingleTapConfirmed(MotionEvent e)
    boolean  onSingleTapUp(MotionEvent e)
    解釋:上面這兩個函數都是在touch down后又沒有滑動(onScroll),又沒有長按(onLongPress),然后Touchup時觸發。
    點擊一下非常快的(不滑動)Touchup:
    onDown->onSingleTapUp->onSingleTapConfirmed
    點擊一下稍微慢點的(不滑動)Touchup:
    onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed


    posted @ 2011-02-16 15:03 九寶 閱讀(540) | 評論 (0)編輯 收藏

    onNewIntent 什么時候調用

    protected void onNewIntent (Intent intent)

    Since: API Level 1

    This is called for activities that set launchMode to "singleTop" in their package, or if a client used theFLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.

    An activity will always be paused before receiving a new intent, so you can count on onResume() being called after this method.

    Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.


    在IntentActivity中重寫下列方法:onCreate onStart onRestart  onResume  onPause onStop onDestroy  onNewIntent
    一、其他應用發Intent,執行下列方法:
    I/@@@philn(12410): onCreate
    I/@@@philn(12410): onStart
    I/@@@philn(12410): onResume

    發Intent的方法:
    Uri uri = Uri.parse("philn://blog.163.com");
    Intent it = new Intent(Intent.ACTION_VIEW, uri);    
    startActivity(it);

    二、接收Intent聲明:
     <activity android:name=".IntentActivity" android:launchMode="singleTask"
                      android:label="@string/testname">
                 <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data android:scheme="philn"/>
                </intent-filter>
      </activity>

    三、如果IntentActivity處于任務棧的頂端,也就是說之前打開過的Activity,現在處于
    I/@@@philn(12410): onPause
    I/@@@philn(12410): onStop 狀態的話
    其他應用再發送Intent的話,執行順序為:
    I/@@@philn(12410): onNewIntent
    I/@@@philn(12410): onRestart
    I/@@@philn(12410): onStart
    I/@@@philn(12410): onResume

    posted @ 2011-02-14 11:18 九寶 閱讀(6204) | 評論 (1)編輯 收藏

    Observer模式在J2EE中的實現 [http://35java.com/zhibo/forum.php?mod=viewthread&tid=108&extra=page%3D3]

    引言:
                設計模式是經驗的文檔化。它是對被用來在特定場景下解決一般設計問題的類和相互通信的對象的描述。更通俗的來說,它是一個問題/解決方案對。一旦我們掌握了設計模式,就等于擁有了一支強有力的專家隊伍。它甚至能夠使面向對象的新手利用前人的經驗找出職責明確的類和對象,從而獲得優雅的解決方案。由于設計模式也是重構的目標,如果在設計的初期適當地引入設計模式,可以減少重構的工作量。
          但是,我們也不能陷入模式的陷阱,為了使用模式而去套模式,那樣會陷入形式主義。我們在使用模式的時候,一定要注意模式的意圖(intent),而不要過多的去關注模式的實現細節,因為這些實現細節在特定情況下,可能會發生一些改變。不要頑固地認為設計模式一書中的類圖或實現代碼就代表了模式本身。
          下面,我們來討論一下為什么要在分布式、多層系統中使用Observer模式。
          

    多層體系結構(multi-tier architecture):
                三層體系結構是多層體系結構中最簡單的一種,它一般包括:
          
    • 表示層(presentation)-窗口、報表-
    • 業務邏輯層(business logic)-管理業務過程的任務和規則。它又可以細分為領域對象層(代表領域概念)和服務層(提供數據庫交互、安全性、打印報表)。
    • 存儲層(storage)-持久化存儲機制。如數據庫服務器等。
                  
    圖一:三層體系結構
                  
          而Java 2平臺企業版(J2EE)是一種利用Java 2平臺來簡化諸多與多級企業解決方案的開發、部署和管理相關的復雜問題的體系結構。它是開放的、基于標準的平臺,用以開發、部署和管理N層結構、面向Web的,以服務器為中心的企業級應用。
          為了支持領域對象的復用,并且使領域對象的接口變更所帶來的影響最小化。我們將領域層(模型)和表示層(視圖)相分離。
          采用模型-視圖模式的意義在于:
          
    • 支持聚合度更高的模型定義,使模型的定義可以集中在領域過程的定義,而不是圖形界面上。
    • 允許將模型和用戶界面并行開發。
    • 使用戶界面的需求變化對領域層所造成的影響最小化。
    • 允許建立與一個現有的領域層對象相連接的新視圖,同時不影響領域層。
    • 允許一個模型同時有多個視圖,例如使用SVG和表格。
    • 允許模型層獨立于用戶界面層執行。
          而這恰恰與Observer模式的意圖相吻合。因此我們有必要跨層來實現Observer模式。
          其實,在應用中更多的是采用MVC框架來架構整個企業應用的。在MVC框架中,Model和View之間存在著依賴關系,是Observer模式的典型應用。當然MVC框架還包括其它模式如Composite模式和Strategy模式。在J2EE平臺中,我們可以把Web Tier(包括Jsp和servelet和JavaBean)看作是表示層,EJB Tier看作是領域層。而controller可能跨距Web Tier和 EJB Tier。
          在Java類庫中采用Java.util.Observable類和Java.util.Observer接口來實現Observer模式,它們在單個的Java VM.中運行的很好,但如果想在EJB中使用它們就會有一些問題。這正如我們引言中提到的,模式的具體實現在特定情況下,可能會發生一些改變。
          

    值傳遞還是遠程引用傳遞?
                        值傳遞:        
    在Java RMI中要求所有的參數和返回類型是JAVA的基本類型或實現Java.io.Serilizable的對象。串行化對象通過值傳遞(又名拷貝傳遞),而不是引用傳遞,這意味著在某一層中串行化對象的更并不自動影響到其它的對象。      
                  遠程引用傳遞:        
    對于EJB對象而言,它由兩個接口(home接口和remote接口)和一個類組成。容器會根據ejb規范來生成實現上面兩個接口的類(我們分別稱為xxxEJBHome對象和xxxEjbObject對象)。在較多的容器的實現方案中,xxxEJBHome對象使用了factory模式來創建xxxEjbObject對象;xxxEjbObject對象則采用proxy模式,作為xxxBean的代理類。在生成以上兩個對象的同時,容器會從部署文件中讀取關于安全、事務、持久性等服務并在xxxEjbObject對象和xxxEJBHome對象中添加以上服務的代碼。而且xxxEJBHome對象和xxxEjbObject對象都是分布式對象,我們在此只討論xxxEjbObject對象。所謂分布式對象,從本質上來講,分為3個部分:object server、skeleton、stub。其中object server和skeleton位于服務器端,而stub位于客戶端。Object server負責實現業務邏輯,skeleton負責marshal和unmarshal方法簽名。      
                  
    圖二:分布式對象
                  
          顯然,EJB的客戶(調用EJB的對象)可以是任何對象,包括EJB和一般的Java類甚至是用任何語言寫的corba客戶端。
          從EJB的客戶視角來看的話,我們只能看到一個home接口、一個remote接口(對于實體bean的話,還可以看見一個主鍵類,而bean類對客戶是不可見的)。但我們從上面的論述,我們可以知道,對于remote接口中地方法調用,實際上是多態地調用XXX_Stub類。即XXX_Stub對象對客戶具有可見性(但這種可見性是透明的,即客戶不知道這種可見性的存在)。由于,XXX_Stub對象和Object Server實現了相同的接口,并且Object server真正實現了業務邏輯。所以,當在客戶端調用XXX_Stub對象的方法時候,XXX_Stub對象通過socket通信機制將方法簽名傳給XXX_Skeleton對象,XXX_Skeleton對象在去委托Object Server完成業務處理邏輯。因此,Object Server本身發生了改變。我們稱XXX_Stub對象是Object Server對象的遠程引用,并認為當分布式對象作為參數傳遞的時候,是通過引用傳遞的(會產生副作用

    posted @ 2011-02-13 19:24 九寶 閱讀(422) | 評論 (0)編輯 收藏

    RMI的定義(轉)http://blog.csdn.net/ocean181/archive/2010/09/02/5857273.aspx

    RMI的定義

    Java RMI (Remote Method Invocation 遠程方法調用)是用Java在JDK1.1中實現的,它大大增強了Java開發分布式應用的能力。Java作為一種風靡一時的網絡開發語言,其巨大的威力就體現在它強大的開發分布式網絡應用的能力上,而RMI就是開發百分之百純Java的網絡分布式應用系統的核心解決方案之一。其實它可以被看作是RPC的Java版本。但是傳統RPC并不能很好地應用于分布式對象系統。而Java RMI 則支持存儲于不同地址空間的程序級對象之間彼此進行通信,實現遠程對象之間的無縫遠程調用。

    RMI目前使用Java遠程消息交換協議JRMP(Java Remote Messaging Protocol)進行通信。JRMP是專為Java的遠程對象制定的協議。因此,Java RMI具有Java的“Write Once,Run Anywhere”的優點,是分布式應用系統的百分之百純Java解決方案。用Java RMI開發的應用系統可以部署在任何支持JRE(Java Run Environment Java,運行環境)的平臺上。但由于JRMP是專為Java對象制定的,因此,RMI對于用非Java語言開發的應用系統的支持不足。不能與用非Java語言書寫的對象進行通信。

    RMI與CORBA的關系

    RMI 和CORBA常被視為相互競爭技術,因為兩者都提供對遠程分布式對象的透明訪問。但這兩種技術實際上是相互補充的,一者的長處正好可以彌補另一者的短處。RMI 和 CORBA 的結合產生了 RMI-IIOP,RMI-IIOP 是企業服務器端 Java 開發的基礎

    1997 年,IBM 和 Sun Microsystems啟動了一項旨在促進 Java 作為企業開發技術的發展的合作計劃。兩家公司特別著力于如何將 Java 用作服務器端語言,生成可以結合進現有體系結構的企業級代碼。所需要的就是一種遠程傳輸技術,它兼有 Java 的 RMI(Remote Method Invocation,遠程方法調用)較少的資源占用量和更成熟的 CORBA(Common Object Request Broker Architecture,公共對象請求代理體系結構)技術的健壯性。出于這一需要,RMI-IIOP問世了,它幫助將 Java 語言推向了目前服務器端企業開發的主流語言的領先地位。

    RMI的組成

    一個正常工作的RMI系統由下面幾個部分組成:

    1、遠程服務的接口定義

    2、遠程服務接口的具體實現

    3、樁(Stub)和框架(Skeleton)文件

    4、一個運行遠程服務的服務器

    5、一個RMI命名服務,它允許客戶端去發現這個遠程服務

    6、類文件的提供者(一個HTTP或者FTP服務器)

    7、一個需要這個遠程服務的客戶端程序

    RMI的實現

    下面我們一步一步建立一個簡單的RMI系統。首先在你的機器里建立一個新的文件夾,以便放置我們創建的文件,為了簡單起見,我們只使用一個文件夾存放客戶端和服務端代碼,并且在同一個目錄下運行服務端和客戶端。

    如果所有的RMI文件都已經設計好了,那么你需要下面的幾個步驟去生成你的系統:

    1、   編寫并且編譯接口的Java代碼
    2、   編寫并且編譯接口實現的Java代碼
    3、   從接口實現類中生成 Stub 和 Skeleton 類文件
    4、   編寫遠程服務的主運行程序
    5、   編寫RMI的客戶端程序
    6、   安裝并且運行RMI系統

    1、接口

    第一步就是建立和編譯服務接口的Java代碼。這個接口定義了所有的提供遠程服務的功能,下面是源程序:

       1. //Calculator.java
       2. //define the interface
       3. import java.rmi.Remote;
       4.
       5. public interface Calculator extends Remote
       6. {
       7.     public long add(long a, long b)
       8.         throws java.rmi.RemoteException;
       9.
      10.     public long sub(long a, long b)
      11.         throws java.rmi.RemoteException;
      12.
      13.     public long mul(long a, long b)
      14.         throws java.rmi.RemoteException;
      15.
      16.     public long div(long a, long b)
      17.         throws java.rmi.RemoteException;
      18. }


    注意,這個接口繼承自Remote,每一個定義的方法都必須拋出一個RemoteException異常對象。

    建立這個文件,把它存放在剛才的目錄下,并且編譯。

    >javac Calculator.java

    2、接口的具體實現

    下一步,我們就要寫遠程服務的具體實現,這是一個CalculatorImpl類文件:

       1. //CalculatorImpl.java
       2. //Implementation
       3. import java.rmi.server.UnicastRemoteObject;
       4.
       5. public class CalculatorImpl extends UnicastRemoteObject implements Calculator
       6. {
       7.
       8.     // 這個實現必須有一個顯式的構造函數,并且要拋出一個RemoteException異常
       9.     public CalculatorImpl()
      10.         throws java.rmi.RemoteException {
      11.         super();
      12.      }
      13.
      14.     public long add(long a, long b)
      15.         throws java.rmi.RemoteException {
      16.         return a + b;
      17.      }
      18.
      19.     public long sub(long a, long b)
      20.         throws java.rmi.RemoteException {
      21.         return a - b;
      22.      }
      23.
      24.     public long mul(long a, long b)
      25.         throws java.rmi.RemoteException {
      26.         return a * b;
      27.      }
      28.
      29.     public long div(long a, long b)
      30.         throws java.rmi.RemoteException {
      31.         return a / b;
      32.      }
      33. }


    同樣的,把這個文件保存在你的目錄里然后編譯他。

    這個實現類使用了UnicastRemoteObject去聯接RMI系統。在我們的例子中,我們是直接的從UnicastRemoteObject 這個類上繼承的,事實上并不一定要這樣做,如果一個類不是從UnicastRmeoteObject上繼承,那必須使用它的exportObject() 方法去聯接到RMI。

    如果一個類繼承自UnicastRemoteObject,那么它必須提供一個構造函數并且聲明拋出一個RemoteException對象。當這個構造函數調用了super(),它久激活UnicastRemoteObject中的代碼完成RMI的連接和遠程對象的初始化。

    3、Stubs 和Skeletons

    下一步就是要使用RMI編譯器rmic來生成樁和框架文件,這個編譯運行在遠程服務實現類文件上。

    >rmic CalculatorImpl

    在你的目錄下運行上面的命令,成功執行完上面的命令你可以發現一個Calculator_stub.class文件,如果你是使用的Java2SDK,那么你還可以發現Calculator_Skel.class文件。

    4、主機服務器

    遠程RMI服務必須是在一個服務器中運行的。CalculatorServer類是一個非常簡單的服務器。

       1. //CalculatorServer.java
       2. import java.rmi.Naming;
       3.
       4. public class CalculatorServer {
       5.
       6.    public CalculatorServer() {
       7.      try {
       8.         Calculator c = new CalculatorImpl();
       9.        Naming.rebind("rmi://localhost:1099/CalculatorService", c);
      10.       } catch (Exception e) {
      11.        System.out.println("Trouble: " + e);
      12.       }
      13.     }
      14.
      15.    public static void main(String args[]) {
      16.      new CalculatorServer();
      17.     }
      18. }


    建立這個服務器程序,然后保存到你的目錄下,并且編譯它。

    5、客戶端

    客戶端源代碼如下:

       //CalculatorClient.java
       
        import java.rmi.Naming;
        import java.rmi.RemoteException;
        import java.net.MalformedURLException;
       import java.rmi.NotBoundException;
       
       public class CalculatorClient {
       
           public static void main(String[] args) {
             try {
                 Calculator c = (Calculator)
                                  Naming.lookup(
                        "rmi://localhost
                                /CalculatorService");
                   System.out.println( c.sub(4, 3) );
                System.out.println( c.add(4, 5) );
                   System.out.println( c.mul(3, 6) );
                  System.out.println( c.div(9, 3) );
                }
               catch (MalformedURLException murle) {
                   System.out.println();
                  System.out.println(
                     "MalformedURLException");
                   System.out.println(murle);
                }
               catch (RemoteException re) {
                  System.out.println();
                   System.out.println(
                              "RemoteException");
                   System.out.println(re);
               }
              catch (NotBoundException nbe) {
                  System.out.println();
                   System.out.println(
                              "NotBoundException");
                   System.out.println(nbe);
                }
               catch (
                   java.lang.ArithmeticException
                                             ae) {
                  System.out.println();
                  System.out.println(
                   "java.lang.ArithmeticException");
                 System.out.println(ae);
                }
           }
       }

    保存這個客戶端程序到你的目錄下(注意這個目錄是一開始建立那個,所有的我們的文件都在那個目錄下),并且編譯他。

    6、運行RMI系統

    現在我們建立了所有運行這個簡單RMI系統所需的文件,現在我們終于可以運行這個RMI系統啦!來享受吧。

    我們是在命令控制臺下運行這個系統的,你必須開啟三個控制臺窗口,一個運行服務器,一個運行客戶端,還有一個運行RMIRegistry。

    首先運行注冊程序RMIRegistry,你必須在包含你剛寫的類的那么目錄下運行這個注冊程序。

    >rmiregistry

    好,這個命令成功的話,注冊程序已經開始運行了,不要管他,現在切換到另外一個控制臺,在第二個控制臺里,我們運行服務器CalculatorService,因為RMI的安全機制將在服務端發生作用,所以你必須增加一條安全策略。以下是對應安全策略的例子
    grant {
    permission java.security.AllPermission "", "";
    };

    注意:這是一條最簡單的安全策略,它允許任何人做任何事,對于你的更加關鍵性的應用,你必須指定更加詳細安全策略。

    現在為了運行服務端,你需要除客戶類(CalculatorClient.class)之外的所有的類文件。確認安全策略在policy.txt文件之后,使用如下命令來運行服務器。

    > java -Djava.security.policy=policy.txt CalculatorServer

    這個服務器就開始工作了,把接口的實現加載到內存等待客戶端的聯接。好現在切換到第三個控制臺,啟動我們的客戶端。

    為了在其他的機器運行客戶端程序你需要一個遠程接口(Calculator.class) 和一個stub(CalculatorImpl_Stub.class)。 使用如下命令運行客戶端

    > java -Djava.security.policy=policy.txt CalculatorClient

    如果所有的這些都成功運行,你應該看到下面的輸出:
    1
    9
    18
    3

    如果你看到了上面的輸出,恭喜你,你成功了,你已經成功的創建了一個RMI系統,并且使他正確工作了。即使你運行在同一個計算機上,RMI還是使用了你的網絡堆棧和TCP/IP去進行通訊,并且是運行在三個不同的Java虛擬機上。這已經是一個完整的RMI系統。

    posted @ 2011-02-13 18:46 九寶 閱讀(258) | 評論 (0)編輯 收藏

    JavaBean PropertyChange 之設計模式Observer(轉)

         摘要: java語言里包含了許多對設計模式的直接支持,如command模式,agent模式,observer模式等。雖然java提供的對這些模式的支持很簡單,不能滿足比較復雜的應用。但在簡單的場景下,使用這些類往往能夠得到立桿見影的效果。所以,如果沒有什么特殊需求,還是最好利用java的這些類。         Observ...  閱讀全文

    posted @ 2011-02-13 18:26 九寶 閱讀(941) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 久久91亚洲精品中文字幕| 久久久久久久久久国产精品免费| 精品无码一区二区三区亚洲桃色 | 亚洲国产精久久久久久久| 内射无码专区久久亚洲| 免费黄色一级毛片| 亚洲精品视频免费看| 久久免费区一区二区三波多野| 永久免费无码网站在线观看个| 亚洲AV日韩AV一区二区三曲| 国产成人精品日本亚洲网址 | 国产精成人品日日拍夜夜免费| 男女污污污超污视频免费在线看| 亚洲色偷偷综合亚洲av78| 亚洲成AV人综合在线观看| 亚洲欧洲日产国产综合网| 亚洲色大成网站WWW久久九九 | 久久国产美女免费观看精品| 四虎影视久久久免费| 特黄特色的大片观看免费视频| 日本亚洲欧美色视频在线播放| 亚洲国产乱码最新视频| 久久精品国产亚洲av麻豆图片| 亚洲五月六月丁香激情| 亚洲欧洲日产国码久在线观看| 亚洲一区二区三区首页| 亚洲视频在线观看| 亚洲va在线va天堂va不卡下载 | 18成禁人视频免费网站| 精品一区二区三区无码免费视频| 免费人成黄页在线观看日本| APP在线免费观看视频| 国产好大好硬好爽免费不卡| 日本免费中文字幕| 51精品视频免费国产专区| 麻豆国产精品免费视频| 18禁超污无遮挡无码免费网站国产| 成人毛片免费网站| 四虎永久在线免费观看| 亚洲伊人久久综合中文成人网| 亚洲一级Av无码毛片久久精品|