
//example.java
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class adduser extends HttpServlet {
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<html><script language=javascript>window.alert('Click Ok to go to Index.jsp')</script></html>");
res.sendRedirect("index.jsp");
}
}

Please go through the following link:
The above link will provide you an example that will call javascript method prompt. Similarly, you can call alert method.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.