如何简单的实现springmvc进行调用

2025-05-10 06:13:39
推荐回答(1个)
回答1:

1. 配置web.xml


SSM

index.jsp



springMVC
org.springframework.web.servlet.DispatcherServlet


contextConfigLocation
classpath:springmvc.xml




springMVC

*.action




2.配置springmvc.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">






















leilei

leilei













3.controller
public class ItemsController2 implements HttpRequestHandler {

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

ArrayList list = new ArrayList<>();

list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");

request.setAttribute("list", list);

request.getRequestDispatcher("/WEB-INF/jsp/a.jsp").forward(request, response);

}

}