Spring mvc 的HelloWorld出现异常 调试两天还不行 高人

J2EE 码拜 8年前 (2016-03-20) 901次浏览
最近学习spring mvc前天还好好的helloworld程序 可是今天忽然不能用了 照着以前的代码运行无法打开
输入http://localhost:8080/springmvc/queryItems.action 显示 HTTP Status 500 – Servlet.init() for servlet springmvc threw exception  异常如下  求高人指点 两天快疯了被搞得 实在找不出什么问题网上的例子也都搜完了
Spring mvc 的HelloWorld出现异常 调试两天还不行 高人
springmvc.xml  配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  
 
 <context:component-scan base-package="com.ssm.controller"></context:component-scan>
 
  <!-- 处理器适配器 将bean的name作为url进行查找 ,需要在配置Handler时指定beanname(就是url) 
	全部的映射器都实现 HandlerMapping接口。 -->
  <bean   class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
  
  
  
 	 <!-- 配置Handler  将编写的Handller在映射器加载 ,name一定要写成url -->
	<bean  id="itemsController" name="/queryItems.action" class="com.ssm.controller.ItemsController1" />


	<!-- 处理器映射器 将bean的name作为url进行查找 ,需要在配置Handler时指定beanname(就是url) 
	全部的映射器都实现 HandlerMapping接口。
	-->
	<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
	<!-- 视图解析器
	解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包
	 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

	</bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>springmvc</display-name>
  
  <!-- springmvc前端控制器 -->
  <servlet>
  	<servlet-name>springmvc</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:springmvc.xml</param-value>
  	</init-param>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>springmvc</servlet-name>
  
  	<url-pattern>*.action</url-pattern>
  </servlet-mapping>
  
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

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<Items> itemsList = new ArrayList<Items>();
				//向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;
	}
}
解决方案

27

假如你使用了jre 1.8,那么需要spring 4 的支持

27

错误报的是参数异常,传参出了问题

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Spring mvc 的HelloWorld出现异常 调试两天还不行 高人
喜欢 (0)
[1034331897@qq.com]
分享 (0)