开发者

Problem displaying popup ( java 1.4 )

I have a JSP with some fields. When I fill in the fields and click the send button, I have to go check that the data in database exists; if it does not, I display a popup alerting the user that the data does not exist in the database. If they choose to continue anyway it goes on the screen; if not it returns to the starting point.

I'm stuck at where I display the popup, since the server can not display the pop开发者_开发百科up on the client


Just let Servlet store the condition in request scope and let JSP print the Javascript code conditionally.

Servlet:

boolean exist = yourDAO.exist(parameters);
request.setAttribute("exist", exist);
request.getRequestDispatcher("page.jsp").forward(request, response);

JSP (using JSTL):

<c:if test="${!exist}">
    <script>
        if (confirm('Data does not exist, do you want to continue?')) {
            // Do whatever you want when user want to continue ("goes on screen").
        } else {
            // Do whatever you want when user don't want to continue ("returns to starting point").
        }
    </script>
</c:if>


I would do somethign along the lines of the following:

First, set a boolean flag while doing your database check

<%
    boolean POPUP_FLAG = /*condition check*/
%>

Then later, if your rendering code, you can check the flag and include a window.open in the page as appropriate

<%
  if (POPUP_FLAG) {
%>
    <script>
    window.open("popup.jsp", "_blank");
    </script>
    /*
      Include here any special details to display on the main page in popup mode
    */
<%
  } else {
%>
    /*
      Include here the normal information you would want displayed when not in popup mode
    */
<%
  }
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜