index page submit button call controller方法,但显示“spring mvc crud中的http404错误”

n53p2ov0  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(269)

我尝试使用hibernatetemplate创建一个SpringMVCCrud应用程序。我的索引页显示,但控制器在提交表单后显示错误。我检查了很多次,但没有发现问题。请让我知道我的错误。谢谢你的忠告。这是密码。。。
索引.jsp

<input type="button" onclick="location.href='Register/form'" value="Register">

控制器

@Controller
@RequestMapping("/Register")
public class RegisterController {
    StudentDao dao;

    @RequestMapping("/form")
    public String form(Model m) {
        m.addAttribute("command",new Student());
        return "formpage";
    }
    //create
    @RequestMapping(value="/save",method=RequestMethod.POST)
    public String save(@ModelAttribute("student") Student student) {
        dao.saveStudent(student);
        return "redirect:/GetAll";
    }}

表单页.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Add Student</title>
</head>
<body>
<form:form method="post" action="save">
<table>
<tr><td><form:input path="Name"/></td></tr>
<tr><td><form:input path="Age"/></td></tr>
<tr><td><form:input path="Qualification"/></td></tr>
<tr><td><form:input path="Mobile"/></td></tr>
<tr><td><input type="submit" value="Save"/></td></tr>
</table>
</form:form>
</body>
</html>

spring-servlet.xml

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

<!-- For scan all classes or beans and controllers -->        

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

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/crudDec20"></property>
<property name="username" value="root"></property>
<property name="password" value="pass"></property>
</bean>

<bean id="mySessionId" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list><value>
student.hbm.xml
</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>

<bean id="d" class="com.uc.StudentDao">
<property name="template" ref="template"></property>
</bean>

<bean id="contoller" class="com.uc.RegisterController">
<property name="dao" ref="d"></property></bean>

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

</beans>

网站.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_1.xsd" 
 id="WebApp_ID" version="3.0">  
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
  <servlet-name>spring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  <servlet-name>spring</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题