【问题标题】:How to call the post method of a servlet?如何调用servlet的post方法?
【发布时间】:2017-05-08 11:42:09
【问题描述】:

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

【问题讨论】:

    标签: java android servlets httpclient


    【解决方案1】:

    当你创建一个 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>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    相关资源
    最近更新 更多