Hi,
I would like to achieve the following.  I would like
to send the contents of an XML file from one servlet
on one server in USA to another servlet in another
server in Canada and that should then be downloaded
into a local file.  Any ideas on what I should do?  I
have included the code that I have put in the doPost
method.

Send.Java (Send Servlet)
------------------------
   public void doPost(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException
    {
        ServletContext context = getServletContext();
        String filename = new String();

        try
        {

            filename =
request.getParameter("filename");

            if (filename == null) filename = "";

            if (filename.trim().length() != 0)
            {

                response.setContentType("text/xml");

                PrintWriter out   = new
PrintWriter(new BufferedWriter(response.getWriter()));
                BufferedReader in = new
BufferedReader(new FileReader(filename));
                String textLine;

                while ((textLine = in.readLine()) !=
null)
                {
                    out.println(textLine);
                }
                in.close();
                out.close();
            }
            else
            {
                response.setContentType("text/html");
                PrintWriter pw = response.getWriter();
                pw.println("File name not passed");
                pw.close();
            }

        }
        catch(Exception e)
        {
            log("Failed to send contents.");
        }


    }

Receive.Java (Receive Servlet)
------------------------------

    public void doPost(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException
    {
        ServletContext context = getServletContext();
        boolean receiveFlag = false;

        response.setContentType("text/html");
        PrintWriter output = response.getWriter();

        try
        {
            if
(request.getContentType().equals("text/xml"))
            {

                output.println("Received " +
request.getContentType() + " content.");
                output.println("<br>");

                PrintWriter out   = new
PrintWriter(new BufferedWriter(new
FileWriter("foo.out")));
                BufferedReader in = new
BufferedReader(request.getReader());
                String textLine;

                while ((textLine = in.readLine()) !=
null)
                {
                    out.println(textLine);
                }
                in.close();
                out.close();

                output.println("Received " +
intToString(request.getContentLength()) + " bytes of
content.");
                output.println("<br>");
                receiveFlag = true;

            }
        }
        catch(Exception e)
        {
            output.println("Failed to receive/write
locally, " + intToString(request.getContentLength())
+
                "bytes of content.");
            output.println("<br>");
            receiveFlag = false;
        }


    }

SEND.HTML
---------
<FORM METHOD=POST
ACTION="http://hostname/servlet/send"; name=dataform>
<TABLE>
        <TR>
                <TD>File to send</TD>
                <TD><INPUT TYPE="file" NAME="filename"></TD>
        </TR>
        <TR>
                <TD></TD>
                <TD><INPUT TYPE="submit" value="Send"></TD>
        </TR>
        </TABLE>
</FORM>



When I invoke the send servlet in the browser via a
HTML page which is used to select the XML file to
send,  I keep getting the browser's download dialog on
a continous basis.

Any help would be appreciated.

David Gowe

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

___________________________________________________________________________
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