gpt4 book ai didi

java - Spring MVC 匹配通配符严格错误

转载 作者:行者123 更新时间:2023-12-02 04:01:03 24 4
gpt4 key购买 nike

我正在尝试在 spring mvc 中编写一个程序,但出现错误。这是程序

index.jsp

<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"/>
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
omit-xml-declaration="true" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Welcome</title>
</head>
<body>
<a href="welcome">Welcome Guest</a>
</body>
</html>
</jsp:root>

HelloController.java

package java4s;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.ModelMap;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.ArrayList;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;

import java4s.EmployeeService;
@Controller
public class HelloController {

@Autowired
EmployeeService emp_service;

@RequestMapping("/welcome")
public ModelAndView helloWorld(@ModelAttribute("userForm") Employee employee, ModelMap model) {

String message = "Welcome to Java4s.com Spring MVC 4.1.1 Sessions";
message += "<br>You Did it....!";
List<String> professionList = new ArrayList();
professionList.add("Developer");
professionList.add("Designer");
professionList.add("IT Manager");
model.put("professionList", professionList);
return new ModelAndView("welcomePage", "welcomeMessage", new Employee());
}
@RequestMapping(value = "/addemployee", method=RequestMethod.POST)
@DateTimeFormat(pattern="MM/dd/yyyy")
public ModelAndView submitForm(ModelMap model, @ModelAttribute("userForm") Employee employee/*, BindingResult errors*/) {

/*if(errors.hasErrors())
{
model.addAttribute("studenterrors", "Errorsssss");
}*/
//System.out.println(student.getBirthdate());
//model.addAttribute("studenterrors", "Errorsssss");
model.addAttribute("username", employee.getUsername());
model.addAttribute("password", employee.getPassword());
model.addAttribute("birthdate", employee.getBirthdate());
model.addAttribute("email", employee.getEmail());
model.addAttribute("professionList", employee.getProfession());
model.addAttribute("userForm", new Employee());

emp_service.saveData(employee);
return new ModelAndView("RegisterSuccess",model);
}

}

EmployeeServiceImpl.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package java4s;

import java4s.Employee;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;

/**
*
* @author Harshit Shrivastava
*/
public class EmployeeServiceImpl implements EmployeeService {

@Autowired
DataSource dataSource;

@Override
public void saveData(Employee employee)
{

String query = "INSERT INTO EmployeeInfo(userid,username,firstname,lastname,mobileno,emailid,password,profession) VALUES(?,?,?,?,?,?,?,?)";

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);


}
}

欢迎-servlet.xml

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

<context:component-scan base-package="java4s" />
<mvc:annotation-driven />
<bean id="EmployeeService" class="java4s.EmployeeServiceImpl" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="oracle.jdbc.pool.OracleDataSource"
p:url="jdbc:oracle:thin:@localhost:1521:IM"
p:username="user"
p:password="pass" />
</beans>

每当我提交表单时,都会收到此错误。错误:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML document from ServletContext resource [/WEB-INF/welcome-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 27; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.

最佳答案

将您的 xml 更改为 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 如下。

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

<context:component-scan base-package="java4s" />
<mvc:annotation-driven />
<bean id="EmployeeService" class="java4s.EmployeeServiceImpl" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="oracle.jdbc.pool.OracleDataSource"
p:url="jdbc:oracle:thin:@localhost:1521:IM"
p:username="user"
p:password="pass" />
</beans>

关于java - Spring MVC 匹配通配符严格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34891460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com