服务器报错 而且一直重复报 页面插入一次数据 数据库插入了多条一样 的数据啊
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:494)
at org.apache.struts.action.RequestProcessor.processLocale(RequestProcessor.java:621)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:177)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)

解决方案 »

  1.   

    at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
    at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)楼主看一下 这一段异常时不时出现了多次,
    我想估计应该是你有某个地方写错了。
    既然插入数据库的数据存在就说明dao  应该没有错。。
    我想应该是你提交了多次,
    最好楼主可以吧 代码贴出来
      

  2.   

    public interface CategoryDao {
    public void save(Category category);

    public void delete(int id);

    public void update(Category category);

    public Category get(int id);

    public List<Category> find();

    public List<Category> find(int offset,int pageSize);
    }
    public class CategoryDaoImpl extends HibernateDaoSupport implements
    CategoryDao{
    public void delete(int id) {
    getHibernateTemplate().delete(get(id));
    }
    public List<Category> find() {
    List<Category> categories = (List<Category>) getHibernateTemplate().execute(new HibernateCallback(){
    @Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    List<Category> category = session.createCriteria(Category.class).list();
    return category;
    }

    }); return categories;
    }
    public List<Category> find(final int offset, final int pageSize) {
    List<Category> categories = (List<Category>) getHibernateTemplate().execute(new HibernateCallback(){ @Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    List<Category> category = session.createCriteria(Category.class).setFirstResult((offset-1)*pageSize).setMaxResults(pageSize).list();
    return category;
    }

    });
    return categories;
    }
    public Category get(final int id) {
    Category category = (Category)getHibernateTemplate().execute(new HibernateCallback(){ @Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    Category category =  (Category)session.createCriteria(Category.class).add(Restrictions.eq("id", id)).list().get(0);
    return category;
    }

    });
    return category;
    }
    public void save(Category category) {
    getHibernateTemplate().save(category);
    }
    public void update(Category category) {
    getHibernateTemplate().saveOrUpdate(category);
    }
    }
    public interface CategoryService {

    public void addCategory(Category category);

    public void deleteCategory(int id);

    public void updateCategory(Category category);

    public Category getCategory(int id);

    public List<Category> findCategories();

    public List<Category> findCategories(int offset,int pageSize);


    }
    public class CategoryServiceImpl implements CategoryService {

    private CategoryDao categoryDao;

    public CategoryDao getCategoryDao() {
    return categoryDao;
    } public void setCategoryDao(CategoryDao categoryDao) {
    this.categoryDao = categoryDao;
    } @Override
    public void addCategory(Category category) {
    categoryDao.save(category);
    } @Override
    public void deleteCategory(int id) {
    categoryDao.delete(id);
    } @Override
    public List<Category> findCategories() {
    List<Category> categories = categoryDao.find();
    return categories;
    } @Override
    public List<Category> findCategories(int offset, int pageSize) {
    return categoryDao.find(offset, pageSize);
    } @Override
    public Category getCategory(int id) {
    return categoryDao.get(id);
    } @Override
    public void updateCategory(Category category) {
    categoryDao.update(category);
    }}
    public class CategoryAction extends DispatchAction { private CategoryService categoryService;


    public CategoryService getCategoryService() {
    return categoryService;
    } public void setCategoryService(CategoryService categoryService) {
    this.categoryService = categoryService;
    } public ActionForward unspecified(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    List<Category> categories = categoryService.findCategories();
    request.setAttribute("categories", categories);
    return mapping.findForward("listCategories");
    }

    public ActionForward addUI(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    return mapping.findForward("addUI");
    }

    public ActionForward add(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    CategoryForm categoryForm = (CategoryForm) form;
    Category category = new Category();
    category.setName(categoryForm.getName());
    categoryService.addCategory(category);

    return mapping.findForward("showCategory");
    }

    public ActionForward editUI(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    CategoryForm categoryForm = (CategoryForm)form;
    Category category = categoryService.getCategory(categoryForm.getId());

    categoryForm.setName(category.getName());
    return mapping.findForward("editUI");
    }

    public ActionForward edit(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    CategoryForm categoryForm = (CategoryForm) form;
    Category category = new Category();
    category.setName(categoryForm.getName());
    categoryService.updateCategory(category);
    return mapping.findForward("showCategory");
    }

    public ActionForward delete(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    CategoryForm categoryForm = (CategoryForm) form;
    categoryService.deleteCategory(Integer.parseInt(request.getParameter("id")));
    return mapping.findForward("showCategory");
    }

    public ActionForward changeOrder(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    return super.execute(mapping, form, request, response);
    }


    }
      

  3.   

    估计是“提交数据的Action类的方法”写的有问题。
      

  4.   

    public interface CategoryDao {
    public void save(Category category);public void delete(int id);public void update(Category category);public Category get(int id);public List<Category> find();public List<Category> find(int offset,int pageSize);
    }
      

  5.   

    public class CategoryDaoImpl extends HibernateDaoSupport implements
    CategoryDao{
    public void delete(int id) {
    getHibernateTemplate().delete(get(id));
    }
    public List<Category> find() {
    List<Category> categories = (List<Category>) getHibernateTemplate().execute(new HibernateCallback(){
    @Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    List<Category> category = session.createCriteria(Category.class).list();
    return category;
    }});return categories;
    }
    public List<Category> find(final int offset, final int pageSize) {
    List<Category> categories = (List<Category>) getHibernateTemplate().execute(new HibernateCallback(){@Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    List<Category> category = session.createCriteria(Category.class).setFirstResult((offset-1)*pageSize).setMaxResults(pageSize).list();
    return category;
    }});
    return categories;
    }
    public Category get(final int id) {
    Category category = (Category)getHibernateTemplate().execute(new HibernateCallback(){@Override
    public Object doInHibernate(Session session)
    throws HibernateException, SQLException {
    Category category = (Category)session.createCriteria(Category.class).add(Restrictions.eq("id", id)).list().get(0);
    return category;
    }});
    return category;
    }
    public void save(Category category) {
    getHibernateTemplate().save(category);
    }
    public void update(Category category) {
    getHibernateTemplate().saveOrUpdate(category);
    }
    }
      

  6.   

    public interface CategoryService {public void addCategory(Category category);public void deleteCategory(int id);public void updateCategory(Category category);public Category getCategory(int id);public List<Category> findCategories();public List<Category> findCategories(int offset,int pageSize);
    }
    public class CategoryServiceImpl implements CategoryService {private CategoryDao categoryDao;public CategoryDao getCategoryDao() {
    return categoryDao;
    }public void setCategoryDao(CategoryDao categoryDao) {
    this.categoryDao = categoryDao;
    }@Override
    public void addCategory(Category category) {
    categoryDao.save(category);
    }@Override
    public void deleteCategory(int id) {
    categoryDao.delete(id);
    }@Override
    public List<Category> findCategories() {
    List<Category> categories = categoryDao.find();
    return categories;
    }@Override
    public List<Category> findCategories(int offset, int pageSize) {
    return categoryDao.find(offset, pageSize);
    }@Override
    public Category getCategory(int id) {
    return categoryDao.get(id);
    }@Override
    public void updateCategory(Category category) {
    categoryDao.update(category);
    }}
      

  7.   

    通过dug模式,从action-service-dao一部一部调式,可以解决问题。