惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - 小牛哥

招聘.NET软件工程师 2人 招聘.NET软件工程师 2人 招聘.NET高级程序员[深圳] Windows 2003不能用 '..' 表示父目录解决方法 使用JS创建虚拟目录,并引导进入浏览 判断一个字符是否为汉字 无法打开 Web 项目“DottextWeb”问题的解决 如何解决一个小问题:当前不会命中断点 Lucene.Net的问题我找到了,郁闷 插入表情图标的功能 事务死锁的问题如何解决? 创建虚拟目录和移除虚拟目录 - 小牛哥 - 博客园 Unclean shutdown of previous Apache run? - 小牛哥 VB.NET实现Singleton模式 启动一个进层阻止当前线程 使用DataReader填充DataTable Asc和Chr 获得一个随机数 将Html代码转换为Text
Migration from J2EE to .NET
小牛哥 · 2004-11-23 · via 博客园 - 小牛哥

Migration from J2EE to .NET
by vivek devarajan.

Hi all, here are some quick tips to get you started, in case you need to migrate a J2EE based application to a .NET based application.

We approach the migration tier wise. Firstly, a technology mapping between both the platforms :--

Service or Feature .NET J2EE
GUI WinForms SWING & AWT
Web GUI ASP.NET JSP
Web Scripting ISAPI, HttpHandler, HttpModule Servlet, Filter
Server Side Business Logic Component Serviced Component (COM+) EJB Session Beans
Server side Data component Serviced Component (COM+) with DB Logic EJB BMP Entity Beans
Server Side Data Component Object Spaces EJB CMP Entity Beans
Naming ADSI JNDI
Remote Invocation .NET Remoting RMI or RMI-IIOP
Data Access ADO.NET JDBC
Messaging MSMQ JMS
Transactions COM+ or MTS JTA

Highlights of the migration strategy

  1. Presentation Tier JSP -> ASP.NET
  2. Business Logic Tier EJB -> COM+ (.NET Enterprise Service)
  3. Data Access Tier JDO/JDBC -> ADO.NET

i. Presentation tier migration

  1. JSP -> ASP .NET (sample code snippets)

    JSP scriptlet :--

    <!--Scriptlet--> 
    
    <%
          for(int i = 0; i < 3; i++) {
                out.println(i + "<br>"); 
          }
    %>
    ASP .NET scriptlet :--
    <!--Scriptlet-->
    <%
          for(int i = 0; i < 3; i++) {
                Response.Write(i + "<br>");
          }
    %>
    JSP expression :--
    <%= new java.math.BigDecimal(10.1).negate() %>
    ASP .NET expression :--
    <%= System.Decimal.Negate(new System.Decimal(10.1)) %>
    JSP declaration :--
    <%!
          public String foo() {
                return "foo";
          }
    %>
    ASP .NET declaration :--
    <script runat="server" language="c#">
          public virtual string foo() 
          {
                return "foo";
          } 
    </script>
  2. Implicit objects :--
    JSP ASP .NET
    application Application
    session Session
    request Request
    response Response
    out Response.Write

  3. Cookies :--

    Creating a cookie and setting its expiry time.

    Code in J2EE :--

    <%
          Cookie userCookie = new Cookie("user", "uid123");
          userCookie.setMaxAge(60*60*24*365); // 1 year
          response.addCookie(userCookie);
    %>
    Code in .NET :--
    <%
          System.Web.HttpCookie userCookie = 
                new System.Web.HttpCookie("user", "uid123");
          System.DateTime dateTime = System.DateTime.Now;
          System.TimeSpan timeSpan =
                new System.TimeSpan(0, 0, 60*60*24*365); // 1 year
          
          cookie.Expires = dateTime.Add(timeSpan);
          Response.Cookies.Add(userCookie); 
    %>
  4. Beans :--

    Java code :--

    public class Bean1 {
    
          private String text = "Hello";
          
          public Bean1 () {}
          
          public String getText() {
                return this.text;
          }
          
          public String setText(String text) {
                this.text = text;
          }
    }
    C# code :--
    using System; 
    
    public class Bean1{
    
          private string text = "Hello";
          
          public Bean1() {} 
    
          public string Text
          {
                get { return text; }
                set { text = value; }
          }
    }
  5. Converting Servlets to ASP .NET code behind :--

    Servlet sample code :--

    import javax.servlet.*; 
    import javax.servlet.http.*;
    
    import java.io.*;
    
    public class SimpleServlet extends HttpServlet {
    
          public void doGet(HttpServletRequest request, 
                      HttpServletResponse response)
                      throws ServletException, java.io.IOException {
                
                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                
                out.println("<html><body>");
                out.println("Simple Servlet Body");
                out.println("</body></html>");
                
                out.close();
          }
    }
    ASP .NET code-behind sample :--
    using System; 
    using System.Web; 
    using System.Web.UI; 
    
    public class SimpleServlet : System.Web.UI.Page
    {
          private void Page_Load(object sender, EventArgs args)
          {
                Response.ContentType = "text/html";
                
                Response.Write("<html><body>");
                Response.Write("Simple Servlet Body");
                Response.Write("</body></html>");
          }
    }
  6. Tag Library :--
    JSP ASP .NET
    Tag Handler Class
    JSP Tag Library Descriptor
    JSP Tag Library Directive
    ASP.NET Web User Controls
    ASP.NET Web Custom Control

    JSP tag lib Sample code :--
    <!?JSP --> 
    <!?the source file is specified in the TLD --> 
    
    <%@ taglib uri="taglib.tld" prefix="tags" %> 
    
    <tags:sample />
    ASP .NET tag lib Sample code :--
    <!?ASP.NET --> 
    
    <%@ Register TagPrefix="tags" TagName="sample"
          Src="ExampleTag.ascx" %> 
    
    <tags:sample id="mySample" runat="server" />
  7. Converting Java Applets to .NET Winforms control :--

    Applet code :--

    package helloWorldPackage; 
    
    public class HelloWorld extends Applet {
    
          public void paint(Graphics g) {
                g.drawString(getParameter("parameter1"), 25, 25);
          }
          
          public void init() {}
          public void start() {}
          public void stop() {}
    }
    .NET Winforms code :--
    namespace HelloWorldPackage
    {
          public class HelloWorld : System.Windows.Forms.UserControl
          {
                string parameter1;
                bool isActive;
                
                public HelloWorld()
                {
                      init();
                }
                
          protected override void OnPaint(PaintEventArgs e)
          {
                e.Graphics.DrawString(parameter1, Font,
                      new SolidBrush(ForeColor), 25, 25);
          }
          
          public void init()
          {
                this.GotFocus +=
                      new EventHandler(this.helloWorldControl1_Start);
                this.LostFocus +=
                      new EventHandler(this.helloWorldControl1_Stop);
          }
    }

ii. Business tier migration

  1. Migrating EJB to .NET Serviced Component

    EJB code :-- (Session bean)

    public class TellerBean implements SessionBean {
    
          public void ejbCreate() {}
          public void ejbRemove() throws RemoteException {}
          public void ejbActivate() throws RemoteException {}
          public void ejbPassivate() throws RemoteException {}
          
          public String getData() {
                return "some data";
          }
    }
    .NET code :-- (serviced component corresponding to the java session bean)
    [Transaction(TransactionOption.Required)] 
    public class TellerBean : System.EnterpriseServices.ServicedComponent
    {
          public virtual string Data
          {
                get { return "some data"; }
          }
    
          public void Create() {}
          protected override void Activate() {}
          protected override void Deactivate() {} 
          
          protected void Remove {
                Deactivate();
                Dispose();
          }
    }
    EJB Code :-- (Entity Bean)
    public class AccountEntity implements EntityBean { 
    
      private string accountID;
      private int balance;
    
      public getAccountID() { ?}
    
      public getBalance() { ?}
      public setBalance(int amount) { ?}
     
    }

    public class AccountProcess implements EntityBean { 
    
      public AccountEntity[] inquiry() { ?}; 
    
      public void insert(AccountEntity account) {
          string strQuery = "SELECT * FROM tb_account";
          ?
      }
    
      public void update(AccountEntity account) { ?}
      public void delete(string accountID) { ?}
    }
    .NET Code :-- (serviced component corresponding to the Java Entity Bean)
    [Transaction(TransactionOption.Required)] 
    public struct AccountEntity
    {
          private string accountID;
          private int balance;
          
          public AccountID {
                get { ?}
          }
          
          public Balance
          {
                get { ?}
                set { ?}
          }
    }

    // DSAccount.xsd 
    
    public class DSAccount : System.Data.DataSet
    {
      ?
    } 
    
    public class AccountProcess : System.EnterpriseServices.ServicedComponent 
    {
          public DSAccount Inquiry()
          {
                ?
          }
    
          public void Insert(AccountEntity account)
          {
                DBAgent.ExecuteNonQuery("sp_getAccount", paramArray, ?;
                ?
          }
    
          public void Insert(string accountID, int balance, ?)
          {
                ?
          } // Alternative
    }

    CREATE PRODECURE sp_getAccount
          @accountID char(8),
          @balance int,
          ?
    AS
          ..
  2. Business Client Tier

    Java Code :--

    <%
          try {
                Context ctx = new InitialContext();
                Object ref = ctx.lookup("TellerHome");
                
                tellerHome = (TellerHome)PortableRemoteObject.narrow(ref,
                      TellerHome.class);
                teller = tellerHome.create();
                
                out.println(teller.getData());
    
          }catch(Exception ex) {
                out.println(ex.getMessage());
          }
    %>
    .NET Code :--
    <%
          MyPackage.TellerBean teller = new MyPackage.TellerBean();
          Response.Write(teller.Data);
    %>

iii. Data tier migration

  1. Database connection

    Java :-- (JDBC)

    Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
    dbUrl = "jdbc:odbc:ADOTEST";
          
    conn = DriverManager.getConnection(dbUrl,"sa","");
    .NET (ADO.NET) :--
    dbUrl = "Provider=SQLOLEDB;Data Source=dbserver;Initial Catalog=Master;";
    
    using(OleDbConnection conn = new OleDbConnection(dbUrl))
    {
          conn.Open();
          ...
    }
  2. Statement object :--

    Java :-- (JDBC)

          Statement s = conn.createStatement();
          createTableBooks = "SELECT count(au_lname) as nrows FROM authors";
    
          ResultSet rs = s.executeQuery(createTableBooks);
    .NET (ADO.NET)
    string cmdText = "SELECT count(au_lname) as nrows FROM authors";
    
    using(OleDbCommand cmd = new OleDbCommand(cmdText, conn))
    {
          OleDbDataReader rs = cmd.ExecuteReader();
          ...
    }