views:

910

answers:

5

I am trying to understand what's the correspondent of servlets and applets in .NET but I don't have much experience in JAVA.

I am thinking applets could be compared to the silverlight stuff, meaning you code independently from the browser, but then it's not like that since (between other things) you can re-use an applet outside the browser.

I need to demonstrate web technologies for a JAVA-based college-course and I can use .NET as long as I can demonstrate the same stuff.

Any help or ideas appreciated!

+1  A: 

The counterpart to Applets in .NET were ActiveX controls. Silverlight is meant for RIA, something analogous to Adobe Flash runtime.

Servlets can be compared to ASP.NET pages. On how they compare end-to-end read the following article on MSDN, http://msdn.microsoft.com/en-us/library/aa478987.aspx

Sandy
No I guess, ASP.NET is more like JSP, or may be even more like JSF.
Adeel Ansari
I'd say the classic was basically ASP is the equivalent of JSP
JohnIdol
With codebehind model ASP.NET more or less comes equivalent to the Servlet structure where in you can generate everything via the code. The link above explains the subtle difference. But yes, ASP is best compared to JSP.
Sandy
+6  A: 

In .Net, HTTP handlers (.ashx) are probably the closest thing to a servlet. As for applets, there isn't a direct equivelent, but siverlight is probably the closest (although its closer to Flash/JavaFX)

JonoW
HTTP handlers are more equivalent to Servlet fitlers and not Servlets per se. Read the MSDN documentation on the same.
Sandy
I agree with Sandy. AciveX controls are more like Applets than Silverligth
OscarRyz
@Sandy: Do you mean Http Handlers or Http /Modules/. It is the later that provides the capability to "dynamically intercepts requests and responses to transform[...]" (http://java.sun.com/products/servlet/Filters.html).
Richard
+2  A: 

Java applets would seem to have their best analogies to WPF Browser Applications in .NET, if not Silverlight 2.0. There's no perfect mirror between Java and .NET in this respect - some technolgoies seem to be more similar to each other in certain respects and others in different respects. Given that Java was developed largely for the purpose of applets, and the .NET Framework for desktop applications, there are naturally going to be fundamental difference. Although WPF browser applications are of course restricted to the Windows platform (unlike Silverlight), they perhaps resemble applets more greatly in the respect that they can utlise the entire .NET Framework, among other things. Also, as has been pointed out, Silverlight is more analogous to JavaFX.

In terms of servlets, the equivalent is effectively the whole of ASP.NET (moreover the Web Application side as opposed to websites), though that is being slightly vague. Perhaps more accurately, JavaServer Pages most resembles ASP.NET (either WebForms or MVC [Model-View-Controller] for that matter). In the case of the former (Java), content is compiled into Java servlets, whereas in the case of the latter (.NET), content is compiled into .NET assemblies. So maybe .NET assemblies of web applications are most akin to servelets - though to be honest I don't know enough about the Java side of things to make much of a conclusion.

Interestingly, the histories of .NET and Java began somewhat differently (admittedly they were both VM frameworks, and Java inspired .NET), nonetheless in many aspects they have converged over time so that nowadays you'll pretty much find an equivalent technology in either of the two frameworks, though often in one there has been significantly more development and/or success (Silverlight is one example in favour of Microsoft, whereas applets are perhaps in favour of Sun). Anyway, hopefully I've at least provided an overview of where the similarities and differences lie in the two technologies.

Noldorin
what about servlets as .NET HttpHandlers?
JohnIdol
As someone already pointed out in JonoW's answer, I believe Servlet filters are more alike to HttpHandlers.
Noldorin
+2  A: 

I agree with Sandy, ASP.Net is best compared to a JSP (which is really nothing more than a specialized servlet). The .Net servlet analog appears to be the base class System.Web.UI.Page.

This sums up the comparison nicely (examples below blatantly plagiarized)

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();
    }
}
//-----------------//
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>");
    }
}
RG
+1 nice example showing servlet as System.Web.UI.Page with no markup in the aspx - th eother way around seems to be HttpHandler
JohnIdol
+1  A: 

If you are trying to do a demo and you want to show some similarities between .NET and servlets/applets then you may be able to do this: 1) Servlet demo: Create a .aspx file that just goes directly to the codebehind class. Using a browser, call the .aspx file and have the codebehind class respond.

I use servlets as a way to communicate with javascript ajax calls frequently, and in terms of behavior there isn't any difference, my javascript function doesn't know what language or technology it is communicating with.

2) Applet demo: This one is a bit trickier as Silverlight was designed, it seems, to compete with Flash, but you could just make a clock widget and put it up on a webpage, but then you can explain that with some good design either can run outside of the browser as well.

What would be great would be to do your demo in both languages just for a comparison to show that there are multiple ways to approach a problem, and there are trade-offs in which technology to use.

James Black