问答详情
源自:1-3 手工编写第一个Servlet

用 doGet可以显示,用doPost就不显示了 ,哪位好人帮我看一下啊?

<body>
   <h1>第一个servlet小例子</h1>
   <a href="servlet/HelloServlet">get方式请求HelloServlet</a><br>
   <form action="servlet/HelloServlet" method="post">
   <input type="submit" value="用post方式提交HelloServlet" />
   </form>
  </body>
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 System.out.println("处理doGet请求");
		 PrintWriter out=response.getWriter();
		 out.println("HelloServlet");
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 System.out.println("处理doPost请求");
		 PrintWriter out=response.getWriter();
		 out.println("HelloServlet from post");
	}
  <servlet>
  <servlet-name>HelloServlet</servlet-name>
  <servlet-class>servlet.HelloServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>HelloServlet</servlet-name>
  <url-pattern>/servlet/HelloServlet</url-pattern>
  </servlet-mapping>


提问者:慕粉2139036677 2017-03-04 10:55

个回答

  • 袁星
    2017-03-05 15:07:37

    兄弟,显示什么错误?我这边跑你的代码可以诶