使用的是jre1.8 spring4.0 让我百思不得其解的是只要springmvc.xml中出现了

springmvc.xml 配置文件
web.xml
springmvc
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
springmvc
*.action
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
**ItemsController1**
package com.ssm.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.ssm.pojo.Items;
public class ItemsController1 implements Controller{
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//调用service查找 数据库,查询商品列表,这里使用静态数据模拟
List itemsList = new ArrayList();
//向list中填充静态数据
Items items_1 = new Items();
items_1.setName("联想笔记本");
items_1.setPrice(6000f);
items_1.setDetail("ThinkPad T430 联想笔记本电脑!");
Items items_2 = new Items();
items_2.setName("苹果手机");
items_2.setPrice(5000f);
items_2.setDetail("iphone6苹果手机!");
itemsList.add(items_1);
itemsList.add(items_2);
//返回ModelAndView
ModelAndView modelAndView = new ModelAndView();
//相当 于request的setAttribut,在jsp页面中通过itemsList取数据
modelAndView.addObject("itemsList", itemsList);
//指定视图
modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
return modelAndView;
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
com.ssm.controller.*试试
web.xml少了上面这句,把Spring容器集成到 Web 应用里面
楼上正解,因为你没有在web服务器启动的时候加载spring容器。我只是多此一举掺和一下~~~~
楼主,我的问题和你一模一样,弄了很久都找不到原因,你怎么解决的啊?