简体   繁体   中英

how to call multiple servlet form action in single jsp page

Now, i called single servlet form action in single jsp page. I want to call more than one servlet form action in that same jsp page.

I think that you have misunderstood how Servlets work, and what are they used for. Remember that a Servlet is used to serve a client's request and send back a response. Suppose you serve the request of the user in the first servlet.

Why would you want to call another servlet in the same request? 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. You just need to extend your first servlet's functionality.

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.

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); 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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