项目结构
然后再添加一个lib目录 加入所有的jar包 如不省略这一步 Tomcat就会启动失败
导入servlet坐标
javax.servlet javax.servlet-api4.0.1 javax.servlet.jsp javax.servlet.jsp-api2.3.3
编写servlet
package com.cong.controller; import com.cong.service.UserService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; @WebServlet("/Servlet") public class Servlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserService userService = context.getBean(UserService.class); userService.UserServiceSave(); } }
测试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)