[javascript] How to create an alert message in jsp page after submit process is complete

I am trying to add a message in my jsp after the process is done by hitting the submit button.

function onSubmit() {
alert("Master_Data.xlsx and Consistency_Check_Data.xlsx are located under d:/stage/MasterDataReports");
}
</script>
<body>

<form name="input" action="getMasterData" method="get">



    <br />
    <br />
    <h1 align='center'>Master Data File</h1>
    <br />
    <br />


    <table border="0" align='center'>
        <tr>
            <td>
                <h2>Site Name</h2>
            </td>
            <td align='left'>
            <jsp:useBean id="masterDao" class="master.dao.MasterDataDao"/>
            <select name="siteId" id="siteId">
            <option value="0">ALL</option>
             <c:forEach items="${masterDao.allSites}" var="siteDto">
             <option value="${siteDto.id}">${siteDto.name}</option>
            </c:forEach>
            </select></td>
        </tr>
        <tr>
            <td>
                <h2>Division</h2>
            </td>
            <td align='left'>
            <jsp:useBean id="masterDaoUtil" class="master.dao.util.MasterDataConstants"/>
            <select name="divisionId" id="divisionId">
            <option value="33"><%=MasterDataConstants.DIVISION_TYPE_AUDIT_MANAGEMENT_GLOBAL_NAME%></option>
            <option value="31"><%=MasterDataConstants.DIVISION_TYPE_CHANGE_MANAGEMENT_GLOBAL_NAME%></option>
            <option value="34"><%=MasterDataConstants.DIVISION_TYPE_DEA_MANAGEMENT_GLOBAL_NAME%></option>
            <option value="35"><%=MasterDataConstants.DIVISION_TYPE_EHS_MANAGEMENT_GLOBAL_NAME%></option>
            <option value="23"><%=MasterDataConstants.DIVISION_TYPE_EVENT_MANAGEMENT_GLOBAL_NAME%></option>
            </select></td>
        </tr>

    </table>
    <br />
    <br />
    <div style="text-align: center">
        **strong text**<input type="submit" value="Submit" OnClick="onSubmit()">
    </div>

Right now the submit process will only happen after I clear the alert. Is there a way that I can either pop an alert after the submit process is done or if I can add a message to the jsp page? Thanks in advance Sonny

Here is my updated Servlet that is causing error:

package master.service;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
**strong text**import javax.servlet.http.HttpSession;



@SuppressWarnings("serial")

public class MasterDataServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response, HttpSession session)
        throws IOException, ServletException {
    MasterDataService masterDataService = new MasterDataService();
    try {
        int siteId = Integer.parseInt(request.getParameter("siteId"));
        int divisionId = Integer.parseInt(request.getParameter("divisionId"));
        //For master data file
        masterDataService.createMasterDataFile(siteId, divisionId,false);
        //For consistency checker file 
        masterDataService.createMasterDataFile(siteId, divisionId,true);
        request.getRequestDispatcher("/masterDataQueryScreen.jsp").forward(request, response);
        **strong text**session.setAttribute("getAlert", "Yes");//Just initialize a random variable.
        **strong text**response.sendRedirect("/masterDataQueryScreen.jsp");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

This question is related to javascript jsp

The answer is


You can also create a new jsp file sayng that form is submited and in your main action file just write its file name

Eg. Your form is submited is in a file succes.jsp Then your action file will have

Request.sendRedirect("success.jsp")

in your servlet

 request.setAttribute("submitDone","done");
 return mapping.findForward("success");

In your jsp

<c:if test="${not empty submitDone}">
  <script>alert("Form submitted");
</script></c:if>