错误弹簧mvc,hibernate项目(提交表单时)

时间:2017-05-12 13:30:50

标签: java hibernate spring-mvc

我提交注册表时遇到此错误。功能是将用户添加到数据库中。

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for                                      HTTP request with URI [/NumRemembering/] in DispatcherServlet with name 'spring-dispatcher'
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/NumRemembering/register] in DispatcherServlet with name 'spring-dispatcher'

这是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com /xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>NumberRemembering</display-name>
 <servlet>
    <servlet-name>spring-dispatcher</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>
</web-app>    

这是spring-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">


<context:component-scan base-package="com.controller"/>



<bean id="viewResolver"
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
    <value>/WEB-INF/</value>
</property> 
<property name="suffix">
    <value>.jsp</value>
</property>

 </bean>
 <mvc:resources mapping="/resources/**" location="/resources/" />
 <mvc:annotation-driven />
 </beans>

这是hibernate.cfg.xml

 <?xml version="1.0" encoding="UTF-8"?>

      

    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/remember_me</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">Uthpala@123</property>
    <property name="show_sql">true</property>      
    <property name="hbm2ddl.auto">update</property>
    <mapping class="main.java.com.beans.User" />
</session-factory>

这是Login.jsp文件的一部分

        <form action="register" method="post" commandName="user">
                                            <!-- <div class="form-sub-w3ls">
                                                <input placeholder="User Name"  type="text" required="">
                                                <div class="icon-agile">
                                                    <i class="fa fa-user" aria-hidden="true"></i>
                                                </div>
                                            </div> -->
                                            <div class="form-sub-w3ls">
                                                <input placeholder="Email/Username" class="mail" type="email" required="">
                                                <div class="icon-agile">
                                                    <i class="fa fa-envelope-o" aria-hidden="true"></i>
                                                </div>
                                            </div>
                                            <div class="form-sub-w3ls">
                                                <input placeholder="Password"  type="password" required="">
                                                <div class="icon-agile">
                                                    <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                                                </div>
                                            </div>
                                            <div class="form-sub-w3ls">
                                                <input placeholder="Confirm Password"  type="password" required="">
                                                <div class="icon-agile">
                                                    <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- <div class="login-check">
                                         <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><p>I Accept Terms & Conditions</p></label>
                                        </div> -->
                                    <div class="submit-w3l">
                                        <input type="submit" value="Register">
                                    </div>
                                    </form>

这是UserController.java类

package main.java.com.controller;

import java.util.Map;

import main.java.com.beans.User;
import main.java.com.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value="/register", method=RequestMethod.POST)
    public String addUser(@ModelAttribute User user, BindingResult result,    @RequestParam String action, Map<String, Object> map){
    //User userResult = new User();
    userService.add(user);
    //userResult = user;
    //map.put("user", userResult);
    return "success";
     }
}

我已经尝试了很多方法来解决这个问题,但无法解决它。如果有人可以帮助我真的很棒。提前谢谢

0 个答案:

没有答案