ASP.NET 和 Java Servlets/JSP 之间的技术差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3371300/
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-30 01:32:52  来源:igfitidea点击:

Technical differences between ASP.NET and Java Servlets / JSP

c#javaasp.netjspasp.net-mvc-2

提问by knpwrs

My understanding of JSP is that every JSP page on first load is compiled into a Java Servlet. Is this the same for ASPX pages (of course, not into a servlet, but whatever the ASP.NET equivilant is)?

我对 JSP 的理解是,每个 JSP 页面在第一次加载时都会被编译成一个 Java Servlet。这对于 ASPX 页面是否相同(当然,不是进入 servlet,但无论 ASP.NET 等效项是什么)?

What other technicaldifferences should I be aware of with JSP and ASP.NET (MVC 2)?

我应该注意 JSP 和 ASP.NET (MVC 2) 的哪些其他技术差异?

采纳答案by Derrick

JSP pages are translated into Java source code, then compiled into class files (containing Java Byte Code) for future execution. After that, they're actually JIT (Just In Time) compiled by the JVM when they are needed for execution (so they're pretty fast).

JSP 页面被翻译成 Java 源代码,然后编译成类文件(包含 Java 字节码)以供将来执行。之后,它们实际上是在需要执行时由 JVM 编译的 JIT(即时)(因此它们非常快)。

It's my guess that there's a similar process for .NET applications, in that they are compiled into .NET assemblies. This is sort of like Java's class files, except they are IL (Intermediate Language) to run on the CLR. At run time, IL is also translated into native machine instructions for execution.

我猜测 .NET 应用程序有一个类似的过程,因为它们被编译成 .NET 程序集。这有点像 Java 的类文件,除了它们是在 CLR 上运行的 IL(中间语言)。在运行时,IL 也被翻译成本地机器指令以供执行。

The actual build / runtime mechanisms (from a high level) are probably surprisingly similar.

实际的构建/运行时机制(从高层次来看)可能惊人地相似。

EDIT

编辑

Here are some details regarding ASP.NET : http://msdn.microsoft.com/en-us/library/ms366723.aspx

以下是有关 ASP.NET 的一些详细信息:http: //msdn.microsoft.com/en-us/library/ms366723.aspx

Also, with Java based web applications, containers which run them can be configured to pre-compile JSPs when the application is deployed. Then, the JVM loads the class files into memory, and handles JIT compilation / caching from that point forward.

此外,对于基于 Java 的 Web 应用程序,可以将运行它们的容器配置为在部署应用程序时预编译 JSP。然后,JVM 将类文件加载到内存中,并从那时起处理 JIT 编译/缓存。

回答by ewernli

ASP can vaguely compare to JSP / Servlet. ASP.NET can vaguely compare to JSF (build on top of Servlet/JSP).

ASP 可以模糊地与 JSP/Servlet 相提并论。ASP.NET 可以模糊地与 JSF(建立在 Servlet/JSP 之上)相提并论。

ASP.NET and JSF are both component-basedframeworks, while JSP and ASP are mostly viewtechnologies.

ASP.NET 和 JSF 都是基于组件的框架,而 JSP 和 ASP 主要是视图技术。

Done correctly, JSP/Servlet can be used to have an action-basedapproach where a controller process a command and forward to a view for rendering (MVC), which decouple view rendering from the business logic.

如果做得正确,JSP/Servlet 可用于采用基于动作的方法,其中控制器处理命令并转发到视图进行渲染 (MVC),从而将视图渲染与业务逻辑分离。

But the approach taken by component-based framework is different and each component can trigger callbacks (business logic) and is responsible to render itself. They also rely on the concept of data binding, which does not exist as is in action-based framework.

但是基于组件的框架采用的方法不同,每个组件都可以触发回调(业务逻辑)并负责渲染自己。它们还依赖于数据绑定的概念,这在基于动作的框架中是不存在的。

Component-based model are closer to programming model for desktop application, but abstract away the webby nature of the application. This is good and bad at the same time. It's bad when you want to optmize web-related things such as friendly URL, etc. That's I think why Microsoft introduced later on an action-based MVC framework next to ASP.NET.

基于组件的模型更接近桌面应用程序的编程模型,但抽象了应用程序的网络性质。这既是好也是坏。当您想要优化与 Web 相关的事物(例如友好的 URL 等)时,这很糟糕。这就是我认为 Microsoft 后来在 ASP.NET 旁边引入基于动作的 MVC 框架的原因。