在业务控制方法中写入Request,Response等传统web参数
可以在业务控制方法中书写传统web参数,这种方式我们不提倡,耦合了
@Controller @RequestMapping(value="/user") public class UserAction{ @RequestMapping(value="/add",method=RequestMethod.POST) public void add(HttpServletRequest request,HttpServletResponse response) throws Exception{ System.out.println("HelloAction::add()::POST"); int id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); double sal = Double.parseDouble(request.getParameter("sal")); System.out.println(id + ":" + name + ":" + sal); request.getSession().setAttribute("id",id); request.getSession().setAttribute("name",name); request.getSession().setAttribute("sal",sal); response.sendRedirect(request.getContextPath()+"/register.jsp"); } }
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!