java - inter servlet communication -


I have two servicelets: the login circle and the mail circle. Log InSubel queries a MySQL table using jdbc to get a string (email). What I need is to forward this string to MailServlet, which in turn will send an email to the e-mail ID sent by LoginServlet.

My question is how do I call and send mailservlet to login serial from MailServlet? I thought about making an example of MailServlet:

MailServlet servlet = new MailServlet ();

And then use the servlet object to call the function doGet () in MailServlet but I think there is some error in it because this is not the right way to call the sublet How can I call and pass a variable in MailServlet?

The purpose of the servlet is to answer an HTTP request what you should do, your code is refactor, The logic is different from the other servlet and you can use it independently. Therefore, for example, you may end up with a mailman class, and a MailServlet that uses Mailman to do its job.

Edit:

If you have to go to a different page after first hit, then use a redirect:

Edit: For example, suppose you have a servicelet:

  Public class MailServlet HttpServlet {Public Zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException Is, IOException {PrintWriter out = response.getWriter (); Response.setContentType ("text / html"); Message message = new MimeMessage (session1); Message.setFrom (new internet address ("someone@something.com")); Message.setRecipients (...); Message.doSomeOtherStuff (); Transport.send (message); Out.println ("mail has been sent"); Instead, do something like this:  
  The public class mailswatlet extends HTTPsvarlett {Public Zero Depot (HTTPSArlate Request Request, HTTPSRV Response Response) Servlet Upption, IoExation throws {PrintWriter Out = response .getWriter (); Response.setContentType ("text / html"); New Mailer () SendMessage ("someone@something.com", ...); Out.println ("mail has been sent"); }} Public Class Mailer {Public Zero Send Message (By String, ...) {Message Message = New Mime Message (Session 1); Message.setFrom (new internet address ("someone@something.com")); Message.setRecipients (...); Message.doSomeOtherStuff (); Transport.send (message); }}  

Comments