servlet应该执行多少个动作? [英] How many actions should a servlet perform?

查看:132
本文介绍了servlet应该执行多少个动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web开发的新手,我只是想知道java servlet的最佳实践。每个servlet应该只执行一个操作,即用于登录的servlet,用于注册的servlet等,还是应该通过传递一个不同的参数来告诉servlet执行哪个操作来组合类似的操作?

I'm new to web development and am just wondering about best practices for java servlets. Should each servlet perform exactly one action, ie a servlet for login, a servlet for registration etc, or should I look to combine similar actions by passing a different parameter to tell the servlet which action to perform?

干杯

推荐答案

在Struts等框架中,只有一个servlet(尽管可能有多个实例)它的运行)。这个servlet将处理各种URL的请求,并将它们从相关的动作处理程序中传递出去。

In Frameworks such as Struts there is one single servlet (although there could be multiple instances of it running). This servlet will handle requests for various URLs and pass them off the the relevant action handlers.

我最终只编写额外的servlet来提供不同的内容类型,例如图像渲染servlet。

I only end up writing extra servlets for serving different content types such as an image rendering servlet.

这篇关于servlet应该执行多少个动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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