Well, the simple answer is that you're actually doing a GET, when your second servlet 
is expecting a POST. Here's some code that might help.

We had a problem forwarding a person to a forums application. Because we use single 
site login, we wanted to automatically log users into the forum, if they were logged 
in. The problem was that the forum was expecting a POST, and our servlet was doing a 
GET.

—---------------------------------------------------------------------------------------
URL u = new URL("http://my.forums.server/some/forums.cgi");
                URLConnection c = u.openConnection();
                // set the connection to do output to the connection
                c.setDoOutput(true);
                // get the output stream to write to the forums software
                PrintWriter out = new PrintWriter(c.getOutputStream());

                // Preparing buffer for setting data to the forums software
                // writing data to the output stream
                StringBuffer sBuf = new StringBuffer();

                sBuf.append("UserName=");
                sBuf.append(custNum);
                sBuf.append("&Password=");
                out.println(sBuf.toString());
                out.close();

               //Because the servlet is now the client in this case, we read in the 
response from the forums into the servlet, then output to the client;
             BufferedReader inStream
                      = new BufferedReader(new InputStreamReader(c.getInputStream()));
                response.setContentType("text/html");
                java.io.PrintWriter writer = response.getWriter();
                String inputLine;
                while ((inputLine = inStream.readLine()) != null) {
                    writer.println(inputLine);
                }
                writer.flush();
                writer.close();
                inStream.close();
—-----------------------------------------------------------------------------------------------------

There's probably a simpler way to do this, but this worked for us. This isn't exactly 
what you're doing, but you might be able to use it.


>>> "Garg, Anshu (CAP, RAIL)" <[EMAIL PROTECTED]> 07/17/00 12:58PM >>>
I invoke a servlet from an HTML page using method = "POST" and ACTION = "URL
to the servlet1". It works fine.

Now suppose this servlet forwards the request to second HTML page (using
RequestDispathcher). The HTML page invokes second servlet using method =
"POST" and ACTION = "URL to the servlet2". It does not work. The browser
gives the error message "405 Method not allowed".

If I change method from POST to GET, it works fine.

Can you throw some light as to why this is happening.

Anshu Garg

___________________________________________________________________________
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

___________________________________________________________________________
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