如何识别 servlet 中要执行的操作?

发布于 2024-07-30 17:41:11 字数 527 浏览 4 评论 0原文

我正在尝试遵循这个 示例 但我无法理解这部分:
还可以想象 servlet 的上下文路径是 myServer/myApp/servlets。 servlet 容器会将 URL myServer/myApp/createUser.do myServlet 的请求定向到 myServlet,因为请求 URL 与模式 *.do 匹配。 Servlet myServlet 可以从请求 URL 中提取请求的操作的名称。
我无法理解该请求,它不应该是 myServer/myApp/myServlet/createUser.do 吗? 怎样才能提出这样的请求呢? 我可以将 myServlet/createUser.do 放入表单的操作中吗?
谢谢您的宝贵时间。
尤利亚

I am trying to follow this example
but I can't understand this part:
Imagine also that the servlet's context path is myServer/myApp/servlets. The servlet container would direct a request with URL myServer/myApp/createUser.do myServlet to myServlet, because the request URL matches the pattern *.do. Servlet myServlet can extract the requested operation's name from the request URL.
I can't understand the request, shouldn't it be myServer/myApp/myServlet/createUser.do? And how can one create such a request? Can I just put myServlet/createUser.do in the action of a form?
Thank you for your time.
Iulia

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经大条 2024-08-06 17:41:11

不,您为 myapp 创建到 servlet 的映射。 servlet 名称本身通常不会显示在请求 URL 中。 因此,如果匹配,每个发送到 myapp 的请求都将被重定向到您的 servlet。 这意味着您的映射

http://myserver/myapp/*.do

将每个带有 .do 的请求重定向到您的小服务程序。 现在 servlet 必须处理请求 URL(例如为 createUser 渲染视图)

No, you create a mapping to your servlet for myapp. The servlet name itself usually never shows in the request URL. So every request that goes to myapp will be redirected to your servlet if it matches. That means that your mapping

http://myserver/myapp/*.do

redirects every request with a .do to your servlet. Now the servlet has to deal with the request URL (e.g. render the view for createUser)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文