什么时候使用JSP和Servlet? [英] When do you use a JSP and when a Servlet?

查看:604
本文介绍了什么时候使用JSP和Servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序将客户发送到另一个站点来处理付款。在客户之外的另一个站点调用我们服务器上的页面,以告知我们付款的状态。被叫页面检查支付应用程序给出的参数,并检查交易是否为我们所知。然后它会更新数据库以反映状态。这一切都是在没有与客户进行任何交互的情况下完成的。

I have an application that sends the customer to another site to handle the payments. The other site, outside of the customer, calls a page on our server to let us know what the status is of the payment. The called page checks the parameters that are given by the payment application and checks to see whether the transaction is known to us. It then updates the database to reflect the status. This is all done without any interaction with the customer.

我个人选择将此功能作为JSP实现,因为在文件系统中删除文件更容易而不是编译和打包文件,然后在配置文件中添加一个条目。

I have personally chosen to implement this functionality as a JSP since it is easier to just drop a file in the file system than to compile and package the file and then to add an entry into a configuration file.

考虑到页面的功能,我认为servlet将是首选方案。问题是:

  • 我的推定是否正确?

  • 是否有真正的理由在JSP上使用servlet?

  • 这是什么原因?
  • Considering the functionality of the page I would presume that a servlet would be the preferred option. The question(s) are:

  • Is my presumption correct?
  • Is there a real reason to use a servlet over a JSP?
  • What are those reasons?
  • 推荐答案

    将JSP编译为servlet第一次运行。这意味着它们之间没有真正的运行时差异。

    A JSP is compiled to a servlet the first time it is run. That means that there's no real runtime difference between them.

    但是,大多数人都有将servlet用于控制器和JSP用于视图的传统。由于控制器只是java类,因此您可以从所有IDE获得完整的工具支持(代码完成等)。与JSP相比,这提供了更好的质量和更快的开发时间。一些更高级的IDE(IntelliJ IDEA让人想到)有很好的JSP支持,使得这个参数过时。

    However, most have a tradition to use servlets for controllers and JSPs for views. Since controllers are just java classes you can get full tool support (code completion etc.) from all IDEs. That gives better quality and faster development times compared to JSPs. Some more advanced IDE's (IntelliJ IDEA springs to mind) have great JSP support, rendering that argument obsolete.

    如果你正在制作自己的框架或只是简单地制作它JSP,那么你应该随意继续使用JSP。没有性能差异,如果你觉得JSP更容易编写,那么一定要继续。

    If you're making your own framework or just making it with simple JSPs, then you should feel free to continue to use JSPs. There's no performance difference and if you feel JSPs are easier to write, then by all means continue.

    这篇关于什么时候使用JSP和Servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆