在后面的学习中我们会接触到maven,那个时候就不用我们自己这么费劲的导入jar包了
导入springIOC相关jar包、mybatis包、mybatis整个包和jdbc
第二步 在src下创建MVC模式的结构 第三步 配置applicationcontext.xml文件第四步 在web.xml中配置applicationcontext.xml的路径和spring监听器
第五步 在servlet的init()中获取serviceImpl的beancontextConfigLocation classpath:applicationcontext.xml org.springframework.web.context.ContextLoaderListener
public class LoginServlet extends HttpServlet {
private UserService service;
@Override
public void init() throws ServletException {
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
service = (UserServiceImpl) ac.getBean("userService");
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String user = req.getParameter("user");
String pwd = req.getParameter("pwd");
User user1 = service.doLogin(user, pwd);
if(user1!=null){
resp.getWriter().print("success");
}else{
resp.getWriter().print("false");
}
}
}



