How to convert a JSP model 2 application to ASP.NET and C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NoSpamForMe@nospam.com

    How to convert a JSP model 2 application to ASP.NET and C#

    I am currently a java programmer, with some knowledge of the C#
    language but very little knowledge about ASP.NET, and I am know
    wondering if someone can *translate* the java servlet code below to
    ASP.NET/C# ?

    Please note that I am not asking about the best possible way of doing
    the same thing with ASP.NET architecture with those "code behind"
    things I have heard a little about... but what I am asking for is a
    *translation* (other interface/class names and method names...)
    because I want to figure out if it is possible to convert an exisiting
    JSP model 2 application with a quite small effort (search and replace)
    without having to rewrite the entire application with a new
    architecture.

    And yes, I do have read a little about the "Java Language Conversion
    Assistant", but as Micrsoft says it can create support classes and
    "Support classes are sometimes substantially different architecturally
    from the classes they emulate".
    Maybe this conversion assistant also will generate a bunch of code
    behind classes, but I do not want to generate code that I don't really
    understand and will have a hard time to maintain, and that's why I
    want something that is VERY similar to JSP model 2.

    For those of you who now is wondering then why I don't keep the
    application in java instead of bothering about converting it, it is
    because I want to change webhost and the best webhosts I have found
    don't support java, but only ASP.NET.
    (for those of you that now would have a suggestion of a good java
    webhost then I am only interested in webhosts with servers in sweden,
    and the host will have to offer lots of bandwith for the price, and
    all the best ones from this point of view do unfortunately not offer
    java)


    The two essential things in the code below are:

    1)
    How to (from the controller) make model objects accessible from the
    web page. In a java servlet this is done (see below) with the method
    javax.servlet.h ttp.HttpServlet Request.setAttr ibute
    and it can then be accessed from the JSP page with the method
    javax.servlet.h ttp.HttpServlet Request.getAttr ibute

    2)
    How to (from the controller) choose web page to be shown for the user
    In a java servlet this is done (see below) with the method
    javax.servlet.R equestDispatche r.forward

    Here is the code that I would like to see translated into .NET/C# :

    import javax.servlet.h ttp.HttpServlet Request;
    import javax.servlet.h ttp.HttpServlet Response;
    import javax.servlet.h ttp.HttpServlet ;
    public class MyController extends HttpServlet {
    protected void doPost(HttpServ letRequest req, HttpServletResp onse
    resp) throws javax.servlet.S ervletException , java.io.IOExcep tion {

    MyModelClass MyModelObject = new MyModelClass();
    req.setAttribut e("MyModelKey ", MyModelObject);
    req.getRequestD ispatcher("/jspView.jsp").f orward(req, resp);
    }
    }

    Some code that then could be used inside the webpage "jspView.js p" :

    MyModelClass MyModelObject = (MyModelClass)
    req.getAttribut e("MyModelKey") ;
    <%=MyModelOb ject.getSomeDat aToBeShown()% >
Working...