问题描述
我不知道我在哪里出了问题,但是总是出错,说我的数据引入类型不对,请大家帮下我,下面是我的代码:控制台报的错误为:2008-8-18 23:21:23 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() for servlet jsp threw exceptionjava.lang.NumberFormatException: For input string: "name"at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)at java.lang.Integer.parseInt(Integer.java:447)at java.lang.Integer.parseInt(Integer.java:497)at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:153)at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)at org.apache.el.parser.AstValue.getValue(AstValue.java:97)at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:923)at org.apache.jsp.category.categoryList_jsp._jspx_meth_c_005fforEach_005f0(categoryList_jsp.java:129)at org.apache.jsp.category.categoryList_jsp._jspService(categoryList_jsp.java:83)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:965)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:744)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)at java.lang.Thread.run(Thread.java:595)categoryDAO接口:package com.ngworld.bookstore.dao;import java.util.List;public interface CategoryDao extends BaseDao{public List getCategoryList();}categoryHibernate实现类:package com.ngworld.bookstore.hibernate;import java.util.List;import com.ngworld.bookstore.dao.CategoryDao;public class CategoryHibernate extends BaseHibernate implements CategoryDao {public List getCategoryList() {// TODO Auto-generated method stubString hql="from Category p left join p.department order by p.id";return getHibernateTemplate().find(hql);}}categoryService接口:package com.ngworld.bookstore.service;import java.util.List;public interface CategoryService {public List getCategoryList();}categoryManager实现类:package com.ngworld.bookstore.manager;import java.util.List;import com.ngworld.bookstore.dao.CategoryDao;import com.ngworld.bookstore.service.CategoryService;public class CategoryManager implements CategoryService {private CategoryDao categoryDao;public void setCategoryDao(CategoryDao categoryDao) {this.categoryDao = categoryDao;}public List getCategoryList() {// TODO Auto-generated method stubreturn categoryDao.getCategoryList();}}categoryController实现类:package com.ngworld.bookstore.manager;import java.util.List;import com.ngworld.bookstore.dao.CategoryDao;import com.ngworld.bookstore.service.CategoryService;public class CategoryManager implements CategoryService {private CategoryDao categoryDao;public void setCategoryDao(CategoryDao categoryDao) {this.categoryDao = categoryDao;}public List getCategoryList() {// TODO Auto-generated method stubreturn categoryDao.getCategoryList();}}applicationContext-Dao文件:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/hbstpdb?autoReconnect=true&useUnicode=true&characterEncoding=GBK"/> <property name="user" value="root"/> <property name="password" value="root"/> </bean><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><!-- <prop key="show_sql">true</prop><prop key="schema">hbstpdb</prop>--></props></property><property name="mappingResources"><list> <value>com/ngworld/bookstore/vo/Category.hbm.xml</value><value>com/ngworld/bookstore/vo/Bookcategory.hbm.xml</value><value>com/ngworld/bookstore/vo/Department.hbm.xml</value><value>com/ngworld/bookstore/vo/Book.hbm.xml</value><value>com/ngworld/bookstore/vo/Shoppingcart.hbm.xml</value></list></property></bean><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory"><ref local="sessionFactory" /></property></bean><bean id="txProxyTemplate" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true"><property name="transactionManager"><ref bean="transactionManager" /></property><property name="transactionAttributes"><props><prop key="save*">PROPAGATION_REQUIRED,-Exception</prop><prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop><prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop><prop key="update*">PROPAGATION_REQUIRED,-Exception</prop><prop key="*">PROPAGATION_REQUIRED,readOnly</prop></props></property></bean><!-- 目录分类 --><bean id="categoryDao" class="com.ngworld.bookstore.hibernate.CategoryHibernate"><property name="sessionFactory"><ref bean="sessionFactory"/></property></bean>applicationContext-Service配置文件:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <bean id="categoryManagerTarget" class="com.ngworld.bookstore.manager.CategoryManager"><property name="categoryDao"><ref bean="categoryDao"/></property></bean><bean id="categoryService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" parent="txProxyTemplate"><property name="target"><ref bean="categoryManagerTarget"/></property></bean>applicationContext-Servlet配置文件:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors"><list><bean class="com.ngworld.insurancecard.interceptor.RequestEncodingInterceptor"/></list> </property> <property name="mappings"> <props><!-- 目录模块 --> <prop key="/category/categorylist.do">categoryListController</prop></props> </property> </bean><!-- 目录模块 --><bean id="categoryListController" class="com.ngworld.bookstore.controller.category.CategoryListController"><property name="categoryService"><ref bean="categoryService"/></property></bean>我的categroy表:categroyID DepartmentID Name Description1 1 computer computer2 2 science science我的department表:DepartmentID Name Desrciption1 computer computer2 science science这是我的表记录谢谢大家帮我解决下问题,谢谢,这个问题已经困绕我很长时间了!问题补充:抱歉,昨天贴的比较着急忘了贴出pojo文件和hibernate.hbm.xml文件了我在这里补下:pojo文件:category表的pojo文件:package com.ngworld.bookstore.vo;import java.util.HashSet;import java.util.Set;/** * Category generated by MyEclipse Persistence Tools */public class Category extends com.ngworld.bookstore.vo.BaseVo implementsjava.io.Serializable {// Fieldsprivate Integer categoryId;private Department department;private String name;private String description;private Set bookcategories = new HashSet(0);// Constructors/** default constructor */public Category() {}/** minimal constructor */public Category(Department department, String name) {this.department = department;this.name = name;}/** full constructor */public Category(Department department, String name, String description,Set bookcategories) {this.department = department;this.name = name;this.description = description;this.bookcategories = bookcategories;}// Property accessorspublic Integer getCategoryId() {return this.categoryId;}public void setCategoryId(Integer categoryId) {this.categoryId = categoryId;}public Department getDepartment() {return this.department;}public void setDepartment(Department department) {this.department = department;}public String getName() {return this.name;}public void setName(String name) {this.name = name;}public String getDescription() {return this.description;}public void setDescription(String description) {this.description = description;}public Set getBookcategories() {return this.bookcategories;}public void setBookcategories(Set bookcategories) {this.bookcategories = bookcategories;}}department的pojo文件package com.ngworld.bookstore.vo;import java.util.HashSet;import java.util.Set;/** * Department generated by MyEclipse Persistence Tools */public class Department extends com.ngworld.bookstore.vo.BaseVo implementsjava.io.Serializable {// Fieldsprivate Integer departmentId;private String name;private String description;private Set categories = new HashSet(0);// Constructors/** default constructor */public Department() {}/** minimal constructor */public Department(String name) {this.name = name;}/** full constructor */public Department(String name, String description, Set categories) {this.name = name;this.description = description;this.categories = categories;}// Property accessorspublic Integer getDepartmentId() {return this.departmentId;}public void setDepartmentId(Integer departmentId) {this.departmentId = departmentId;}public String getName() {return this.name;}public void setName(String name) {this.name = name;}public String getDescription() {return this.description;}public void setDescription(String description) {this.description = description;}public Set getCategories() {return this.categories;}public void setCategories(Set categories) {this.categories = categories;}}.hbm.xml文件:category.hbm.xml文件<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Mapping file autogenerated by MyEclipse Persistence Tools--><hibernate-mapping> <class name="com.ngworld.bookstore.vo.Category" table="category" > <id name="categoryId" type="java.lang.Integer"> <column name="CategoryID" /> <generator class="increment" /> </id> <many-to-one name="department" class="com.ngworld.bookstore.vo.Department" fetch="select"> <column name="DepartmentID" not-null="true" /> </many-to-one> <property name="name" type="java.lang.String"> <column name="Name" length="50" not-null="true" /> </property> <property name="description" type="java.lang.String"> <column name="Description" length="1000" /> </property> <set name="bookcategories" inverse="true"> <key> <column name="CategoryID" not-null="true" /> </key> <one-to-many class="com.ngworld.bookstore.vo.Bookcategory" /> </set> </class></hibernate-mapping>department.hbm.xml文件:<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Mapping file autogenerated by MyEclipse Persistence Tools--><hibernate-mapping> <class name="com.ngworld.bookstore.vo.Department" table="department"> <id name="departmentId" type="java.lang.Integer"> <column name="DepartmentID" /> <generator class="increment" /> </id> <property name="name" type="java.lang.String"> <column name="Name" length="50" not-null="true" /> </property> <property name="description" type="java.lang.String"> <column name="Description" length="1000" /> </property> <set name="categories" inverse="true"> <key> <column name="DepartmentID" not-null="true" /> </key> <one-to-many class="com.ngworld.bookstore.vo.Category" /> </set> </class></hibernate-mapping>这个是我的jsp文件:<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>分类管理</title></head><body><form action="#" name="frm"><table width="75%" border="1" align="center"> <tr align="center"> <td colspan="4">信息列表</td> </tr> <tr> <td colspan="4">目录管理>>分类管理>>信息管理</td> </tr> <tr> <td>分类编号</td> <td>分类名称</td> <td>部门</td> <td>部门种类</td> </tr> <c:forEach items="${categoryList}" var="categoryList" varStatus="status"> <tr> <td><c:out value="${status.index+1}"/></td> <td>${categoryList.name}</td> <td>${categoryList.department}</td> <td>${categoryList.description }</td> </tr> </c:forEach></table></form></body></html>我知道意思是string类型转化为number类型的错误,但是我不知道哪里出的问题,谢谢大家帮我解决下!问题补充:上面的categoryController文件贴错了这里是我的categoryController文件 package com.ngworld.bookstore.controller.category; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import com.ngworld.bookstore.service.CategoryService; import com.ngworld.bookstore.vo.Category; public class CategoryListController implements Controller{ private CategoryService categoryService; public void setCategoryService(CategoryService categoryService) { this.categoryService = categoryService; } public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub List categoryList=categoryService.getCategoryList(); request.setAttribute("categoryList",categoryList); return new ModelAndView("/category/categoryList.jsp"); } }
解决方案
at org.apache.jsp.category.categoryList_jsp._jspx_meth_c_005fforEach_005f0(categoryList_jsp.java:129) 把你的categoryList.jsp里面的el表达式仔细的检查下, 看是哪个有问题!
解决方案二:
at org.apache.jsp.category.categoryList_jsp._jspService(categoryList_jsp.java:83) 这段报错信息告诉我们是在categoryList.jsp页面的83行报错的。<tr> <td><c:out value="${status.index+1}"/></td> <td>${categoryList.name}</td> <td>${categoryList.department}</td> <td>${categoryList.description }</td> </tr> 如果是这段代码加载数据的话,估计是在加载第10个左右报错的。你看下你加载的数据。
解决方案三:
你的错误的意思是你将string类型的转化为int出的错引用For input string: "name" 这段代码呢?怎么没有啊。。。估计是你哪里定义的数字,但是传进来的是字母,报的错你断点跟下