我是春天的新手,不知道我在哪里弄错了。我正在使用带有eclipse和tomcat的spring 4.0.2 jar。
所有Jar文件:
spring-aop-4.0.2.RELEASE
spring-beans-4.0.2.RELEASE
spring-context-4.0.2.RELEASE
spring-context-support-4.0.2.RELEASE
spring-core-4.0.2.RELEASE
spring-jdbc-4.0.2.RELEASE
spring-jms-4.0.2.RELEASE
spring-orm-4.0.2.RELEASE
spring-test-4.0.2.RELEASE
spring-tx-4.0.2.RELEASE
spring-web-4.0.2.RELEASE
spring-webmvc-4.0.2.RELEASE
commons-logging-1.1.3
的index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>Spring Home Page</h2>
<form name="frmTravel" method="get" action="/SimpleSpringApp/travell">
Travel Name : <input type="text" name="tvlName" />
<input type="submit" value="Submit"/>
</form>
</body>
</html>
的success.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Travel Success</title>
</head>
<body>
<h2>Success Page</h2>
<h3>Here need to show the message</h3>
</body>
</html>
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>SimpleSpringApp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- ddf -->
<servlet>
<servlet-name>Travel</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Travel</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
旅行-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"
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">
<context:component-scan base-package="com.manoj.springprac" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Travel.java:
/**
*
*/
package com.manoj.springprac;
/**
* @author Manoj
*
*/
public class Travel {
private String tvlName;
public String getTvlName() {
return tvlName;
}
public void setTvlName(String tvlName) {
this.tvlName = tvlName;
}
}
TravelController.java:
package com.manoj.springprac;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TravelController {
@RequestMapping(value = "/travell", method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "success";
}
//Here I want to save the data to database also
}
我真的不知道我在哪里错过了配置,以及spring 4.0.x中的SimpleFormController
。
任何建议都会有所帮助。
答案 0 :(得分:5)
我错过了spring-expression jar文件。 我已经添加了它并且工作正常。
您可以从http://mvnrepository.com/artifact/org.springframework/spring-expression/4.0.2.RELEASE
下载答案 1 :(得分:0)
在使用SpringBoot 2.0.0版本时,我在控制台中面临同样的错误。我将Spring-Boot-Starter-Parent的版本更改为1.5.10Release。它对我来说很好。