如何调用servlet的post方法?

时间:2016-12-22 19:03:42

标签: java android servlets httpclient

我是否能够创建servlet的对象并调用post方法并传递所需的参数,或者我必须在web.xml中声明它,如果我在web.xml文件中声明它,我是否可以仍然要从servlet创建一个对象,这是如何工作的? 我试图使用谷歌云存储,我已经在我的一个模块中编译了依赖项,我也有谷歌提供的servlet类。谢谢!

1 个答案:

答案 0 :(得分:0)

当你创建一个servlet时,它有两个常用的方法,GET& POST

public class DemoServlet extends HttpServlet{  
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException  {

    }

    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    }

}

从html页面调用post方法的简便方法是:

<form action="/servlet" method="POST">
  <input type="hidden" name="q" value="a">
</form>
相关问题