Request应用

Request应用,第1张

Request应用 获取前端数据 请求转发
    index.jsp
    
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    
    
    
    <%--${pageContext.request.contextPath}获取当前项目路径,需要导入jsp servlet的依赖包--%>
    
    
    
    
      public class Req extends HttpServlet {
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      
              req.setCharacterEncoding("utf-8");
              resp.setCharacterEncoding("utf-8");
      
              String name = req.getParameter("username");
              String pwd = req.getParameter("password");
              System.out.println(name+":"+pwd);
              String[] hobbys = req.getParameterValues("hobbys");
              System.out.println(Arrays.toString(hobbys));
      
              req.getRequestDispatcher("login.jsp").forward(req,resp);
          }
      
          @Override
          protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              doGet(req, resp);
      
          }
      }
      

      3.注册servlet

      欢迎分享,转载请注明来源:内存溢出

      原文地址: https://outofmemory.cn/zaji/5712529.html

      (0)
      打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
      上一篇 2022-12-18
      下一篇 2022-12-18

      发表评论

      登录后才能评论

      评论列表(0条)

      保存