1.Servlet:
继承javax.servlet.http.HttpServlet;
重写doPost,doGet方法;
2.xml配置bean
public class XAction{
@RequestMapping(value = "/X.do",method = RequestMethod.POST)
public ModelAndView X(HttpServletRequest request,HttpServletResponse response,Model model) {
}
}
<bean name="/X.do" class="com.XXAction"/>
3.注解
@Controller
public class XAction{
@RequestMapping(value = "/XXX.htm", method = RequestMethod.GET)
public ModelAndView getX(Model model,HttpServletRequest request,HttpServletResponse response) {}
}
配置自动扫描
<context:component-scan base-package="com.XAction"/>
<mvc:annotation-driven />
4.实现Controller接口
实现org.springframework.web.servlet.mvc.Controller;
public class XAction implements Controller{
@Override
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
//向前端传递参数
ModelAndView view = new ModelAndView("/XXX");
return view;
}
}