控制器未调度请求的视图

时间:2017-04-28 12:56:04

标签: spring

我是Spring的新手。运行程序后,我收到错误如下....

  

-DispatcherServlet,名称为'dispatcher',处理[/ SpringLoginApp / save]的POST请求    - 请求[/ save]的匹配模式是[/ **]   -URI请求[/ save]的模板变量是{}   -Mapping [/ save]到处理程序的HandlerExecutionChain - [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@5771b5fa]   和1个拦截器-Skip CORS处理:请求来自同一个来源   -Null ModelAndView返回DispatcherServlet,名称为'dispatcher': - 暂停HandlerAdapter完成请求处理    - 已成功完成请求

这是我想要指导的控制器......

  @RequestMapping(value = "/save", method = RequestMethod.POST)

  public String saveEmployee(@ModelAttribute("command")EmployeeBean      
   employeeBean,  BindingResult result) 
 {
   Employee employee = prepareModel(employeeBean);
   employeeService.addEmployee(employee);
   return "redirect:/add";
 }

 @RequestMapping(value = "/add", method = RequestMethod.GET)
 public ModelAndView   addEmployee(@ModelAttribute("command")EmployeeBean employeeBean,BindingResult result)
 {
  Map<String, Object> model = new HashMap<String, Object>();
    model.put("employees",prepareListofBean(employeeService.listEmployeess()));
  return new ModelAndView("addEmployee", model);
 }

这是我的调度员......

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                         http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                         http://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context-4.2.xsd
                         http://www.springframework.org/schema/tx
                         http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">  


 <context:property-placeholder location="classpath:resource/message.properties"/>

   <context:component-scan base-package="com.springLogin.*" />
   <tx:annotation-driven />
   <tx:annotation-driven transaction-manager="hibernateTransactionManager" />
   <mvc:default-servlet-handler/>
    <bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    id="viewResolver">
      <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView"></property>
      <property name="prefix" value="/WEB-INF/views"></property>
      <property name="suffix" value=".jsp"></property>
  </bean>

   <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    id="dataSource">
      <property name="driverClassName" value="${message.driver}"></property>
      <property name="url" value="${message.url}"></property>
      <property name="username" value="${message.user}"></property>
      <property name="password" value="${message.password}"></property>
  </bean>



   <bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.springLogin.entity" />
    <property name="hibernateProperties">
       <props>
          <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}  </prop>
          <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
          <prop key="hibernate.dialect">${hibernate.dialect}</prop>
       </props>
    </property>
  </bean>

   <bean class="org.springframework.orm.hibernate4.HibernateTransactionManager"
    id="hibernateTransactionManager">
       <property name="sessionFactory" ref="sessionFactory"></property>
   </bean> 
 </beans

这是视图请求的表单...

  <form method="POST" action="save" commandName="command">
    <table>
      <tr>
         <td>Employee ID:</td>
          <td><input type="text" name="id" readonly="true"/></td>
      </tr>
     <tr>
         <td>Employee Name:</td>
          <td><input type="text" name="name"/></td>
      </tr>
      <tr>
         <td>Employee Age:</td>
         <td><input type="text" name="age"/></td>
      </tr>
      <tr>
          <td>Employee Salary:</td>
          <td><input type="text" name="salary"/></td>
       </tr>

       <tr>
         <td>Employee Address:</td>
                  <td><input type="text" name="address"/></td>
      < /tr>
         <tr>
       <td colspan="2"><input type="submit" value="Submit"/></td>
      </tr>
 </table> 
 </form>

请原谅我,如果我错了...有什么帮助吗?

0 个答案:

没有答案