So, let's say after receiving the servlet getMasterData will be response.sendRedirect to test.jsp.
In test.jsp
Create javascript
<script type="text/javascript"> function alertName(){ alert("Form has been submitted"); } </script>
and than below
<script type="text/javascript"> window.onload = alertName; </script>
Note: im not sure how to enter code in stackoverflow !. Edit: I just learned
Edit 2: To the question: This works fine. Another question. How can I get rid of the initial warning when I first started JSP? "Form Submitted" is the second one that I execute. It appears after the load is completed, and it will be perfect.
To do this, I would highly recommend using a session!
So what you want to do is your servlet:
session.setAttribute("getAlert", "Yes");
than in test.jsp
<% session.setMaxInactiveInterval(2); %> <script type="text/javascript"> var Msg ='<%=session.getAttribute("getAlert")%>'; if (Msg != "null") { function alertName(){ alert("Form has been submitted"); } } </script>
and than below
<script type="text/javascript"> window.onload = alertName; </script>
Therefore, every time you submit this form, the session will take place! If the session is not equal to zero, the function will be launched!
source share