关于servlet的学习

编写java类 代码 继承 httpservlet 重写doget,dopost 

doPost(HttpServletRequest req, HttpServletResponse resp)

  

doGet(HttpServletRequest req, HttpServletResponse resp)

  req常用方法 

//设置请求的编码
req.setCharacterEncoding(“utf-8”);
//获取请求的参数
req.getParameter(String s)
//获取请求的参数以数组的形式返回
req.getParameterValues(String s)
//转发请求
req.getRequestDispatcher("地址").forward(req,resp);

  写完类后在web.xml中配置对应的servlet

<servlet>
    <servlet-name>多数取类型</servlet-name>
    <servlet-class>com.Reader.download.Down</servlet-class> 包下的类
  </servlet>
  <servlet-mapping>
    <servlet-name>Down</servlet-name>//映射名 多数情况下和上面的name相同
    <url-pattern>/down</url-pattern>//可自配的url链接 必须以/开头
  </servlet-mapping>

  

上一篇:httpServletRequest.getCharacterEncoding()取出来是个null,怎么办?


下一篇:10.5_HttpServletRequest 和 HttpServletResponse