>         Does anyone out there know how to generate a basic looking html
>      page that can be displayed while my java code does database querying?
>         I've seen some sites that generate a page that just says something
>      like "We are searching for your requested records" while the query is
>      being executed.  After execution my results are displayed and the
>      searching page disappears.

     Assuming you're displaying HTML and not an applet, there's no
real way to "push" a new page to the browser.  What you do instead is
include tags in the page to tell the browser to come back and request
another page - to poll the server.  There are a couple different ways
to do this, depending on your target browser.  Haul out your HTML book.
Your best bet is probably something like the META REFRESH tag:

     <meta http-equiv="Refresh" content="30">

     This reloads the page after thirty seconds.  I'm not sure offhand
if using content="0" will immediately redirect or whether you have to
at least delay one second. I haven't checked, so I can't say with
certainty, but refresh'll probably work with almost every browser.

     <meta http-equiv="refresh" content="1" URL="http://mysite/servlet/mycode">

     Actually, this would be a bit more complicated in the URL
section, because you'd have to include the arguments in the URL, in a
GET-style format:

     <meta http-equiv="refresh" content="1"
      URL="http://mysite/servlet/mysearch?target=patterns%in%java&options=verbose">

     I suggest using the REFRESH meta because you specifically want to
display an intermediary page.  If, for some odd reason, you want to
submit the arguments to your servlet and then immediately cause the
browser to resubmit them to somewhere else (presumbably outside of
your control, else you'd just have your servlet transmit the
information there), you can use a LOCATION: redirect.  There's a specific
servlet method to do this, or you could simply print out a header line like:

LOCATION: http://mysite/servlet/mysearch?target=patterns%in%java&options=verbose

     Pick up any good CGI book to get the details about get/post.
O'Reilly's CGI book is probably a good bet. In a nutshell:

     GET requests append the arguments to the URL line (starting with a ?)
     POST requests feed it as a separate piece

     This has to do with an issue in one of the C library functions
that causes a line-length limitation on some GET requests.  In
standard webserver/CGI situations, the server tucks the GET portion of
the request into an environment variable before starting the CGI.  For
POST requests, the server starts the CGI and feeds it the POST data on
STDIN.

     Beyond that, the arguments consist of "name=values" pairs, with
the values "URL encoded" - the spaces are converted to % characters
and some odd punctuation characters are converted to a % plus a
number.  The pairs are delimited with & characters.

     In some cases you might be required to use POST format.  Mainly
I'm thinking about situations where you don't control the script or
servlet you're redirecting to, or where security issues prohibit
putting the arguments in the URL, where they might be bookmarked.  In
such cases, the only way I've found to do it is to generate a page
containing a hidden form and a bit (shudder) javascript to
automatically submit it.

     A hidden form is an HTML form with all of the inputs as
TYPE="hidden".  For example:

<HTML>
  <BODY>
    <FORM METHOD="POST" NAME="my_logon" action="_TARGETURL_" TARGET="_top">
      <INPUT type=HIDDEN name="Login" value="_LOGIN_">
      <INPUT type=HIDDEN name="Password" value="_PASSWORD_">
    </FORM>
    <SCRIPT LANGUAGE="Javascript">
      function autosubmit(theForm) {
            theForm.action="_TARGETURL_" ;
            theForm.submit() ;
      }
      autosubmit(document.my_logon);
    </SCRIPT>
  </BODY>
</HTML>

     Note that the placement of the javascript inside the page is no
accident;  on some browsers emanating from Redmond, the script doesn't
work right unless it's placed as above (if anybody determines that the
above doesn't work on a given flavor of javascript-enabled browser,
please let me know, so I can code a special case in my servlet...).

     I'm reasonably sure all of the above is correct, but I've been up
late coding all night a lot lately, so caveat emptor :-).

Steven J. Owens
[EMAIL PROTECTED]
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to