servlet

Posted zhuxiang1633

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了servlet相关的知识,希望对你有一定的参考价值。

1.servlet基本使用方法

获取参数信息:

技术分享图片
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String username = request.getParameter("username");
        String phone = request.getParameter("username");
        String pwd = request.getParameter("username");
        String[] hobby = request.getParameterValues("hobby");//获取复选框值
        String gender = request.getParameter("gender");
        String course = request.getParameter("course");
        response.getWriter().print("hello");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
RegisterServlet.java

 

以上是关于servlet的主要内容,如果未能解决你的问题,请参考以下文章

servlet和filter的区别

Java基础——JSP

java---servlet与filter的联系与区别

servlet,filter,listener,intercepter区别

Tomcat根据JSP生成Servlet机制解析

servlet,过滤器,监听器,拦截器的区别