Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Handling Time Consuming Requests

Domininic says, "I am try to find a good way to have an intermediate page load up while my Struts Action performs a large database query and then XSLT transformation." Ask and ye shall receive. I received the following e-mail from Alec Missine a while back. The attachment has a method of implementing a TCR. Let me know how it works as I haven't tried it myself.

----- Original Message -----
From: Alec Missine
To: [email protected]
Sent: Monday, January 07, 2002 3:59 PM
Subject: processing time consuming requests (was: wait page primer)


There's been some interest to the message I posted last month on the subject. The war file was too big though, so I compressed the stuff as much as I could. I also added some javadoc and UML diagrams.

The attached Struts-based application prototypes the wait page support for a time-consuming request (TCR). When a TCR (e.g., a database search) starts, the appropriate wait page is being sent to the browser after the request's ETC (Estimated Time to Complete) expires.

In the meantime, the corresponding action (the database search) is being started in the background thread on the server. If the default ETC is used (ad infinitum) or the action completes before the request's ETC expires, there is no wait page at all - the browser gets the result page right away, while the background thread is still busy closing the resources.

The wait page has javascript that polls the server to update the wait page with the TCR's progress. When the TCR completes, the wait page is being replaced with the appropriate result page.

This implementation has been tested on Apache Tomcat 4.0 with an Oracle 8.1.6 database as a data source. Presently, the application provides read-only access to all database tables for all database schemas through extensive use of the java.sql.DatabaseMetaData object. The next release will support insert/update/delete functionality.

Alec

Attachments: tcr.zip (114 KB)

Hope this helps!

Posted in Java at Nov 13 2002, 07:17:28 AM MST 6 Comments
Comments:

Thanks, Will take a look.

Posted by dsuspense on November 13, 2002 at 03:50 PM MST #

Hello, I'm just trying to get this example to work. What versions did you use for each of the jakarta libraries in WEB-INF/lib?

Posted by Leo Hart on July 16, 2003 at 08:24 PM MDT #

I've never even tried to get it to get the example to work. Sorry I can't be of more help - try the struts-user mailing list.

Posted by Matt Raible on July 17, 2003 at 10:50 AM MDT #

What a complicated approach. How about something like this instead? Just set the *.do pattern to be handled by the wait servlet instead of the action servlet, in web.xml.

public class WaitServlet extends HttpServlet {
    //~ Static fields/initializers =============================================

    public static final String WAIT_PARAM = "_wait";

    //~ Methods ================================================================

    protected void doGet(HttpServletRequest httpServletRequest,
                         HttpServletResponse httpServletResponse)
    throws ServletException, IOException {
        doPost(httpServletRequest, httpServletResponse);
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response)
    throws ServletException, IOException {
        if (request.getParameter(WAIT_PARAM) == null) {
            getServletContext().getNamedDispatcher("action").forward(request,
                                                                     response);
        } else {
            PrintWriter out = response.getWriter();
            response.setContentType("text/html");
            out.println("<html><body>");
            out.println("<form action='" + request.getRequestURI() +
                        "' method='POST'>");
            out.println("<div id='content' style='visibility:hidden'>");
            out.println("<br><br><center><h3>Working...</h3></center>");
            out.println("</div>");

            Map params = request.getParameterMap();

            for (Iterator iterator = params.keySet().iterator();
                     iterator.hasNext();) {
                String paramName = (String) iterator.next();

                if (!paramName.equals(WAIT_PARAM)) {
                    String[] paramValue = (String[]) params.get(paramName);

                    for (int i = 0; i < paramValue.length; i++) {
                        out.println("<input type='hidden' name='" + paramName +
                                    "' " + "value='" +
                                    StringUtil.replace(paramValue[i], "'",
                                                       "&apos;") + "'>");
                    }
                }
            }

            out.println("</form>");
            out.println("<script language='javascript1.2' type='text/javascript'>");

            // Wait a second before actually showing the "please wait" content
            out.println(" var tmr = setTimeout('showContent()', 1000);");
            out.println(" document.forms[0].submit();");
            out.println(" function showContent() {");
            out.println(" clearTimeout(tmr)");
            out.println(" var style = document.getElementById? document.getElementById('content').style: " +
                        "(document.layers? document.layers['content']: (document.all? document.all('content').style: null));");
            out.println(" if (!document.getElementById && document.layers) style.visibility = 'show'; else style.visibility = 'visible';");
            out.println(" }");
            out.println("</script>");
            out.println("</body></html>");
        }
    }
}
No threads and its generic

Posted by David Martin on December 06, 2003 at 01:10 PM MST #

Hello David, can I have an example with the use of this WaitServlet? I don't undestand very well how have I to write the web.xml and how to map the ActionServlet. thanks Antonella

Posted by antonella balduzzi on February 11, 2004 at 10:23 AM MST #

Why not do this? This the simplest solution. ..... <script language="JavaScript"> function replaceMainContent(){ document.getElementById("main-content").style.visibility="hidden" ; document.getElementById("loading-content").style.visibility="visible" ; return true; } </script> .... <html:form .... onsubmit="replaceMainContent()"> <div id="main-content"> !!!!Here is your normal content </div> <div id="loading-content" style="visibility: hidden"> !!!! Here is your loading gif or whatever </div> </html:form>

Posted by Pipo Inzagi on May 09, 2007 at 12:28 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed