spring还用的不熟,今天用spring+ibatis做了这个例子
报以下错误:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Cannot create command without commandClass being set - either set commandClass or (in a form controller) override formBackingObject
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:535)。下面是我controller的代码:
public class Springusercontroller extends AbstractCommandController{
private String page;
private String error;
private IuserinfoService service;
@Override
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object voinfo, BindException errors) throws Exception {
uservo user=(uservo)voinfo;
String username=user.getUsername();
String password=user.getPassword();
System.out.println("your username  is "+username);
System.out.println("your password  is "+password);
List list = new ArrayList();
list.add(user);
userinfobo bo=new userinfobo();
bo.setUsername(username);
bo.setPassword(password);
boolean result=service.login(bo);
 if(result==true){
return new ModelAndView(getPage(), "info", list);
        }else{
        return new ModelAndView(getError(), "info", list);
        }
}
public IuserinfoService getService() {
return service;
}
public void setService(IuserinfoService service) {
System.out.println("getService---------");
this.service = service;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}}高手帮忙,多谢,多谢

解决方案 »

  1.   

    我的jsp代码:
    <body bgColor="#dddddd">
    <hr>
    <h2 align="center">
    用户登录

    <form action="login.do" method="post">
    用户名:<input type="text" name="username"><br>
    密&nbsp;&nbsp;码:<input type="password" name="password"><br>

    <input type="submit" value="登 录">
    </form>
    </h2>
    </body>springdemo-servlet.xml内容:<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
    <beans>
    <bean name="/login.do"
    class="com.zq.store.userManagement.view.controller.Springusercontroller">
    <property name="page">
    <value>index</value>
    </property>
    <property name="error">
    <value>error</value>
    </property>
    <property name="service">
    <ref bean="service"/>
    </property>
    </bean> <bean id="service"
    class="com.zq.store.userManagement.biz.impl.UserServiceImpl">
    <property name="dao">
      <ref bean="userinfodao"/>
    </property>
    </bean>


    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
    <value>/jsp/</value>
    </property>
    <property name="suffix">
    <value>.jsp</value>
    </property>
    </bean> <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@localhost:1521:STORE</value>
    </property>
    <property name="username">
    <value>gaoke</value>
    </property>
    <property name="password">
    <value>gaoke</value>
    </property>
    <property name="maxActive">
    <value>60</value>
    </property>
    <property name="maxIdle">
    <value>50</value>
    </property>
    <property name="maxWait">
    <value>5000</value>
    </property>
    </bean> <bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation">
    <value>WEB-INF/SqlMapConfig.xml</value>
    </property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    </bean>
    <bean id="userinfodao" class="com.zq.store.userManagement.dao.impl.userinfoDaoImpl">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="sqlMapClient">
    <ref local="sqlMapClient" />
    </property>
    </bean> <bean id="userDAOProxy"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property>
    <property name="target">
    <ref local="service" />
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    </beans>
      

  2.   

    LZ看看这个 可能对你有帮助
    http://blog.csdn.net/cjoy4856/article/details/5600173