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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.http.HttpServletRequest.setAttribute
and it can then be accessed from the JSP page with the method
javax.servlet.http.HttpServletRequest.getAttribute

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.RequestDispatcher.forward

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
public class MyController extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse
resp) throws javax.servlet.ServletException, java.io.IOException {

MyModelClass MyModelObject = new MyModelClass();
req.setAttribute("MyModelKey", MyModelObject);
req.getRequestDispatcher("/jspView.jsp").forward(req, resp);
}
}

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

MyModelClass MyModelObject = (MyModelClass)
req.getAttribute("MyModelKey");
<%=MyModelObject.getSomeDataToBeShown()% >
 
Back
Top