java .NET中Servlet和Applet的对应关系是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/708800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:28:06  来源:igfitidea点击:

What are the correspondent of Servlet and Applet in .NET?

java.netservletsapplet

提问by JohnIdol

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

我试图了解 .NET 中 servlet 和小程序的对应者是什么,但我在 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.

我认为小程序可以与 Silverlight 的东西相提并论,这意味着您可以独立于浏览器进行编码,但事实并非如此,因为(在其他事情之间)您可以在浏览器之外重新使用小程序。

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.

我需要为基于 JAVA 的大学课程演示 Web 技术,只要我能演示相同的内容,我就可以使用 .NET 。

Any help or ideas appreciated!

任何帮助或想法表示赞赏!

回答by JonoW

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)

在 .Net 中,HTTP 处理程序 (.ashx) 可能是最接近 servlet 的东西。至于小程序,没有直接的等价物,但 siverlight 可能是最接近的(虽然它更接近于 Flash/JavaFX)

回答by nerraga

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.

我同意 Sandy 的观点,ASP.Net 与 JSP(实际上只不过是一个专门的 servlet)相比是最好的。.Net servlet 模拟似乎是基类 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>");
    }
}

回答by Noldorin

Java applets would seem to have their best analogies to WPF Browser Applicationsin .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.

如果不是Silverlight 2.0,Java 小程序似乎与.NET 中的WPF 浏览器应用程序最相似。在这方面,Java 和 .NET 之间没有完美的镜像——一些技术似乎在某些方面彼此更相似,而另一些在不同方面更相似。鉴于 Java 主要是为了小程序而开发的,而 .NET Framework 是为桌面应用程序开发的,自然会有根本的区别。尽管 WPF 浏览器应用程序当然仅限于 Windows 平台(与 Silverlight 不同),但在它们可以使用整个 .NET Framework 等方面,它们可能更类似于小程序。此外,正如已经指出的那样,Silverlight 更类似于 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 Pagesmost 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 applicationsare 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.

就 servlet 而言,等效物实际上是整个 ASP.NET(而且是与网站相对的 Web 应用程序端),尽管这有点含糊。也许更准确地说,JavaServer Pages最类似于ASP.NET(WebForms 或 MVC [Model-View-Controller])。在前者 (Java) 的情况下,内容被编译成 Java servlet,而在后者 (.NET) 的情况下,内容被编译成 .NET 程序集。因此,Web 应用程序的.NET 程序集可能最类似于小服务程序——尽管说实话,我对 Java 方面的了解还不够多,因此无法得出很多结论。

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.

有趣的是,.NET 和 Java 的历史开始有些不同(不可否认,它们都是 VM 框架,Java 启发了 .NET),尽管如此,它们在许多方面随着时间的推移已经融合,因此现在您几乎可以在两者中找到等效的技术在这两个框架中,虽然通常在一个框架中取得了明显更多的发展和/或成功(Silverlight 是支持 Microsoft 的一个例子,而小程序可能支持 Sun)。无论如何,希望我至少概述了这两种技术的异同之处。

回答by sangupta

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

.NET 中 Applet 的对应物是 ActiveX 控件。Silverlight 适用于 RIA,类似于 Adob​​e Flash 运行时。

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

可以将 Servlet 与 ASP.NET 页面进行比较。关于它们如何比较端到端,请阅读 MSDN 上的以下文章,http://msdn.microsoft.com/en-us/library/aa478987.aspx

回答by James Black

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.

如果您正在尝试做一个演示并且想要展示 .NET 和 servlets/applet 之间的一些相似之处,那么您可以这样做: 1) Servlet 演示:创建一个直接进入代码隐藏类的 .aspx 文件。使用浏览器调用 .aspx 文件并让代码隐藏类做出响应。

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.

我经常使用 servlet 作为与 javascript ajax 调用进行通信的一种方式,在行为方面没有任何区别,我的 javascript 函数不知道它正在与哪种语言或技术进行通信。

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.

2) Applet 演示:这个有点棘手,因为 Silverlight 的设计似乎是为了与 Flash 竞争,但您可以制作一个时钟小部件并将其放在网页上,然后您可以通过一些好的设计来解释两者都可以在浏览器之外运行。

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.

最好是用两种语言做你的演示,只是为了进行比较,以表明有多种方法可以解决一个问题,并且需要权衡使用哪种技术。