Migration from J2EE to. net

Source: Internet
Author: User
Tags tld

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 = system. datetime. now; system. 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> 

    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>  
  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.exe cutequery (createtablebooks );

    . Net (ADO. Net)

    String explain text = "select count (au_lname) as nrows from authors"; using (oledbcommand cmd = new oledbcommand (gradient text, Conn) {oledbdatareader rs = cmd. executereader ();...}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.