user1049280
user1049280

Reputation: 5246

GAE handling simple http post request (java)

i'm trying to make out with web-apps on java using google app engine. i have an application that is sending http-post request.

Upvotes: 0

Views: 1328

Answers (1)

Peter Knego
Peter Knego

Reputation: 80340

  1. Create a servlet on GAE that handles the POST:

    public class ExampleAppServlet extends HttpServlet{
        public void doPost(HttpServletRequest req, HttpServletResponse resp) {
    
            // get some data from POST
            InputStream input = req.getInputStream();
    
            // do something with input
    
            // send back some reply
            resp.getWriter().write("Hello Example App").close();
        } 
    } 
    
  2. Map this servlet to URL in web.xml config file:

    <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
        <servlet>
            <servlet-name>example_app_servlet</servlet-name>
            <servlet-class>com.package.ExampleAppServlet</servlet-class>
        </servlet>
        <servlet-mapping>
           <servlet-name>example_app_servlet</servlet-name>
           <url-pattern>/example_app</url-pattern>
        </servlet-mapping>
    </web-app> 
    

Upvotes: 2

Related Questions