Scenario:

1) Several servlets called from one form using javascript (this is using the onClick 
event handler for the form buttons)
2) One servlet serves WAV data, a second serves TIFF data (other servlets behave 
correctly, only the streaming servlets have the problem)
3) The user can select to play WAV data or view TIFF data, however a user cannot view 
WAV data nor play TIFF data
4) Checks are in place (in javascript) to ensure 3 above and an alert box is generated 
when an error is detected

Problem:

1) The user selects WAV data and plays it successfully
2) The user then tries to view the WAV data
3) An alert box comes up telling the user that he/she cannot view the WAV data
4) The user clicks OK on the alert box
5) The WAV data is re-downloaded and played to the user instead of just sitting at the 
selection page

Environment:
Apache 1.3.11 latest release version on Windows NT
Tomcat 3.0
JSDK 2.1 (for compiling servlets, not found on the Apache machine)
JDK 1.2
Browers: IE 5.0 and Netscape Communicator 4.06

I have tried to use the MultipartResponse class in Jason Hunter's "Java Servlet 
Programming" book but to no avail.  Using the javascript function "location.reload()" 
does not work.  It gives a blank page for the main selection screen (this screen is 
also generated by a servlet).

Does anyone know how I can stream data to the browser and then send a redirect?  I 
have included code samples of the javascript functions and the streaming data from the 
servlets.

TIA,
BJ Blinston
[EMAIL PROTECTED]

function playMsg()
{
        theGroup = document.webaccess.actionMsg;
        i = 0;
        nMail=0;
        strMsgId=0;
        nFound = 0;
        if(!theGroup.length)
        {
                nMail = getMsgType(theGroup.value);
                strMsgId = getMsgId(theGroup.value);
                nFound = 1;
        }
        else
        {
                for(i = 0; i < theGroup.length && nFound == 0; i++)
                {
                        if(theGroup[i].checked)
                        {
                                nMail = getMsgType(theGroup[i].value);
                                strMsgId = getMsgId(theGroup[i].value);
                                nFound = 1;
                        }
                }
        }
        if(nFound == 1)
        {
                if(isVoiceMail(nMail))
                {
                        document.webaccess.msgId.value=strMsgId;
                        
document.webaccess.action="/callware/servlet/CwPlayMessageServlet";
                        document.webaccess.method="POST";
                        document.webaccess.submit();
                }
                else
                {
                        alert("Cannot play a fax message!");
                        return true;
                }
        }
        else
        {
                alert("You must select a message before playing!");
                return true;
        }
}
OutputStream os = res.getOutputStream();
res.setContentType("audio/x-wav");
int nBufferSize = baosWavBuffer.size();
byte[] bWavBuffer = baosWavBuffer.toByteArray();
for(int nBufferIndex = 0; nBufferIndex < nBufferSize; nBufferIndex++)
{
        os.write(bWavBuffer[nBufferIndex]);
}
os.flush();

Reply via email to