我不知道我在哪里出了问题,但是总是出错,说我的数据引入类型不对,请大家帮下我,下面是我的代码:
控制台报的错误为:
[code="java"]
2008-8-18 23:21:23 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.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)
[/code]
categoryDAO接口:
[code="java"]
package com.ngworld.bookstore.dao;
import java.util.List;
public interface CategoryDao extends BaseDao{
public List getCategoryList();
}
[/code]
categoryHibernate实现类:
[code="java"]
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 stub
String hql="from Category p left join p.department order by p.id";
return getHibernateTemplate().find(hql);
}
}
[/code]
categoryService接口:
[code="java"]
package com.ngworld.bookstore.service;
import java.util.List;
public interface CategoryService {
public List getCategoryList();
}
[/code]
categoryManager实现类:
[code="java"]
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 stub
return categoryDao.getCategoryList();
}
}
[/code]
categoryController实现类:
[code="java"]
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 stub
return categoryDao.getCategoryList();
}
}
[/code]
applicationContext-Dao文件:
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
org.hibernate.dialect.MySQLDialect
<!--
true
hbstpdb
-->
com/ngworld/bookstore/vo/Category.hbm.xml
com/ngworld/bookstore/vo/Bookcategory.hbm.xml
com/ngworld/bookstore/vo/Department.hbm.xml
com/ngworld/bookstore/vo/Book.hbm.xml
com/ngworld/bookstore/vo/Shoppingcart.hbm.xml
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,readOnly
[/code]
applicationContext-Service配置文件:
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
[/code]
applicationContext-Servlet配置文件:
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<prop key="/category/categorylist.do">categoryListController</prop>
<bean id="categoryListController" class="com.ngworld.bookstore.controller.category.CategoryListController">
<property name="categoryService">
<ref bean="categoryService"/>
</property>
</bean>
[/code]
我的categroy表:
categroyID DepartmentID Name Description
1 1 computer computer
2 2 science science
我的department表:
DepartmentID Name Desrciption
1 computer computer
2 science science
这是我的表记录
谢谢大家帮我解决下问题,谢谢,这个问题已经困绕我很长时间了!
[b]问题补充:[/b]
抱歉,昨天贴的比较着急忘了贴出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 implements
java.io.Serializable {
// Fields
private 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 accessors
public 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 implements
java.io.Serializable {
// Fields
private 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 accessors
public 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">
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">
这个是我的jsp文件:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
分类管理
信息列表 | |||
目录管理>>分类管理>>信息管理 | |||
分类编号 | 分类名称 | 部门 | 部门种类 |
${categoryList.name} | ${categoryList.department} | ${categoryList.description } |
我知道意思是string类型转化为number类型的错误,但是我不知道哪里出的问题,谢谢大家帮我解决下!
[b]问题补充:[/b]
上面的categoryController文件贴错了
这里是我的categoryController文件
[code="java"]
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");
}
}
[/code]