标签:void method exception Servle app dog mamicode color 根据
如果每次都要实现Servlet接口,并重写其方法,个人感觉会很累。
Java是不是提供别的方式呢?
在选中ServletCtrl+T
HttpServlet :用于处理http的请求,而http的请求也就两种(get、post)
继承HttpServlet 复写doGet 和 doPost
1 public class HellowHttpServlet extends HttpServlet { 2 @Override 3 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 4 6 System.out.println("get==="); 7 } 8 9 @Override 10 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 11 13 System.out.println("post---"); 14 } 15 }
配置Servlet
<servlet> <servlet-name>HellowHttpServlet</servlet-name> <servlet-class>com.marw.servlet.HellowHttpServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HellowHttpServlet</servlet-name> <url-pattern>/HellowHttpServlet</url-pattern> </servlet-mapping>
Post请求方式
1 <form action="HellowHttpServlet" method="post"> 2 <input type="submit" value="提交"> 3 </form>
简单的get和post请求
如何根据请求做出对应的响应?
HttpServletRequest对象对应的http的请求信息
HttpServletResponse对象对应的http的响应信息
JavaWeb学习之HttpServletRequest 和 HttpServletResponse
标签:void method exception Servle app dog mamicode color 根据
原文地址:https://www.cnblogs.com/WarBlog/p/12228945.html