2 sujiangchichu sujiangchichu 于 2013.11.26 13:20 提问

SpringMVC程序中的IllegalArgumentException

http://blog.csdn.net/sujiangchichu/article/details/16962231

抛出的的异常:
[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
严重: Servlet.service() for servlet baobaotao threw exception

java.lang.IllegalArgumentException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)

at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:707)

at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:371)

at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4295)

at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:186)

at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134)

at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:995)

at org.hibernate.loader.Loader.doQuery(Loader.java:874)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)

at org.hibernate.loader.Loader.doList(Loader.java:2438)

at org.hibernate.loader.Loader.doList(Loader.java:2424)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)

at org.hibernate.loader.Loader.list(Loader.java:2249)

at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)

at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)

at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)

at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)

at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)

at com.baobaotao.dao.UserDao.findUserByUserName(UserDao.java:34)

at com.baobaotao.service.UserService.findUserByUserName(UserService.java:22)

at com.baobaotao.web.LoginController.loginCheck(LoginController.java:35)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)

at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)

at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)

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.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)

at java.lang.Thread.run(Thread.java:662)

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片

User.dao:
[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
package com.baobaotao.dao;

import java.util.List;

import org.hibernate.Query;

import org.hibernate.Transaction;

import org.springframework.stereotype.Repository;

import com.baobaotao.domain.User;

@Repository //通过spring注解定义一个dao

public class UserDao extends BaseDAO{

public int getMatchCount(String userName, String passWord){  
    String hql = "from User  user "  
            + " where user.userName = ? "  
            + " and user.passWord = ? " ;  
    Query queryObject = getSession().createQuery(hql);  
     queryObject.setParameter(0,userName );  
     queryObject.setParameter(1, passWord);  
     @SuppressWarnings("unchecked")  
    List <User> list=queryObject.list();  
       return list.size();   
}  
public User findUserByUserName(final String userName) {  
    String hql = "from User  user "  
            + " where user.userName = ? ";  

     Query queryObject = getSession().createQuery(hql);  
    queryObject.setParameter(0,userName);  
    User user=(User)queryObject.list().get(0);  
    System.out.println(user);  
return user ;  



}  

public void updateLoginInfo(User user) {  
    Transaction ts=getSession().beginTransaction();  
    getSession().update(user);  
    ts.commit();  
}  

}

LoginController
[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
package com.baobaotao.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

import com.baobaotao.domain.User;

import com.baobaotao.service.UserService;

//标注一个springmvc的Controller

@Controller

public class LoginController {

@Autowired

private UserService userService;

//负责处理index.html的请求  
@RequestMapping(value="/index.html")  
public String loginPage(){  
    return "login";  
}  
//负责处理loginCheck.html的请求  
@RequestMapping(value="/loginCheck.html")  
public  ModelAndView loginCheck(HttpServletRequest request,  LoginCommand loginCommand){  
    boolean isValidUser =   
               userService.hasMatchUser(loginCommand.getUserName(),loginCommand.getPassword() );  

        if (!isValidUser) {  
            return new ModelAndView("login", "error", "用户名或密码错误。");  
        } else {  
            User user = userService.findUserByUserName(loginCommand.getUserName());  
            user.setLastIp(request.getLocalAddr());  
            System.out.println(request.getLocalAddr());  
            user.setLastVisit(new Date());  
            System.out.println(new Date());  
            userService.loginSuccess(user);  

// request.getSession().setAttribute("user", user);

// return new ModelAndView("main");

ModelAndView mv = new ModelAndView();

mv.setViewName("main");

mv.addObject(user);

return mv;

}

}

}

UserService
[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
package com.baobaotao.service;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.baobaotao.dao.LoginLogDao;

import com.baobaotao.dao.UserDao;

import com.baobaotao.domain.LoginLog;

import com.baobaotao.domain.User;

@Service //将userbean标注为一个服务层的Bean

public class UserService {

@Autowired

private UserDao userDao;

@Autowired

private LoginLogDao loginLogDao;

public boolean hasMatchUser(String userName, String passWord){  
    int matchCount = userDao.getMatchCount(userName, passWord);  
    return matchCount>0;  
}  
public User findUserByUserName(String userName){  
    return userDao.findUserByUserName(userName);  
}  
public void loginSuccess(User user){  
    user.setCredits(5+user.getCredits());  
    LoginLog loginLog = new LoginLog();  
    loginLog.setUserId(user.getUserId());  
    loginLog.setIp(user.getLastIp());  
    loginLog.setLoginDate(user.getLastVisit());  
    userDao.updateLoginInfo(user);  
    loginLogDao.insertLoginLog(loginLog);  
}  

}

login.jsp
[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>





hehe









/c:if

" method="post">

用户名:


密 码:










求教,异常如何处理呢?
求教,异常如何处理呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!