Servlet学习笔记

Servlet开发步骤


  1. 继承HttpServlet
  2. 重写doGet和doPost方法
  3. 在web.xml注册servlet(servlet3.0中不需要注册,,选择新建servlet时,系统自动直接使用@webservlet注解)

重写doGet()与doPost()注意事项

  • super.doGet(req, resp);需注释掉(这是调用了父类的方法)
  • 使用PrintWriter时,需用resp.setContentType("text/html;charset=utf-8");//设置显示方式及编码

Servlet与JSP九大内置对象

JSP对象 Servlet中怎样获得
out resp.getWriter
request req参数
response resp参数
session req.getSession()函数
application getServletContext()函数
exception Throwable
page this
pageContext pageContext
Config getServletConfig()函数

Java后台处理form表单提交的复选框数据(字符串数组)

String[] favorites;
favorites = request.getParameterValues("favorite");





原文地址:https://www.cnblogs.com/Val1ant/p/5338900.html