简体   繁体   English

如何在单个jsp页面中调用多个servlet表单动作

[英]how to call multiple servlet form action in single jsp page

Now, i called single servlet form action in single jsp page. 现在,我在单个jsp页面中调用了单个servlet表单动作。 I want to call more than one servlet form action in that same jsp page. 我想在同一jsp页面中调用多个servlet表单动作。

I think that you have misunderstood how Servlets work, and what are they used for. 我认为您误解了Servlet的工作方式以及它们的用途。 Remember that a Servlet is used to serve a client's request and send back a response. 请记住,Servlet用于服务于客户端的请求并发送回响应。 Suppose you serve the request of the user in the first servlet. 假设您在第一个servlet中服务于用户的请求。

Why would you want to call another servlet in the same request? 您为什么要在同一请求中调用另一个servlet? Is it to perform additional functionality that would add nothing on the response? 是否执行其他功能,而不会在响应中添加任何内容? If this is the case then you probably don't need another servlet. 如果是这种情况,那么您可能不需要另一个servlet。 You just need to extend your first servlet's functionality. 您只需要扩展您的第一个servlet的功能。

In the case that you want to call another servlet to add something to the response object, then it's better to revise how your first servlet works, and integrate the functionality of the second servlet in the first one. 如果您要调用另一个servlet来向响应对象添加一些东西,那么最好修改第一个servlet的工作方式,并将第二个servlet的功能集成到第一个servlet中。

If your case is that you want to redirect the user to another jsp/servlet without caring about the response of the first servlet your have the options of request.sebdRedirect("yourJsp.jsp") or request.getRequestDispatcher("yourJsp.jsp").forward(request, response); 如果您的情况是要在不关心第一个servlet响应的情况下将用户重定向到另一个jsp / servlet,则可以选择request.sebdRedirect("yourJsp.jsp")request.getRequestDispatcher("yourJsp.jsp").forward(request, response); And here is their difference. 就是他们的区别。

So, closing all depends upon your business logic... You have to choose the option that fits your needs 因此,全部关闭取决于您的业务逻辑...您必须选择适合您需求的选项

you can't call multiple servlets in one jsp form because the action attribute of form only accepts a single url! 您不能以一种jsp形式调用多个servlet,因为form的action属性仅接受一个URL!

<form method="get" action="/yourservlet"> 
<!-- action only accepts a single url! -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM