The purpose of a servlet is to respond to an HTTP request. What you should do is refactor your code so that the logic you want is separated from the other servlet and you can reuse it independently. So, for example, you might end up with a Mailman class, and a MailServlet that uses Mailman to do its work. It doesn't make sense to call a servlet from another servlet.
If what you need is to go to a different page after you hit the first one, use a redirect:
http://www.java-tips.org/java-ee-tips/java-servlet/how-to-redirect-a-request-using-servlet.html
Edit:
For example, suppose you have a servlet like:
public class MailServlet extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
response.setContentType("text/html");
Message message =new MimeMessage(session1);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(...);
message.doSomeOtherStuff();
Transport.send(message);
out.println("mail has been sent");
}
}
Instead, do something like this:
public class MailServlet extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
response.setContentType("text/html");
new Mailer().sendMessage("[email protected]", ...);
out.println("mail has been sent");
}
}
public class Mailer {
public void sendMessage(String from, ...) {
Message message =new MimeMessage(session1);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(...);
message.doSomeOtherStuff();
Transport.send(message);
}
}