Java 示例SpringMVC应用程序中存在什么问题
我对SpringMVC比较熟悉,我开发了一个示例helloworld应用程序,但在将一个jsp页面导航到另一个jsp页面时出错 **maven项目创建时提供的信息 **项目文件夹结构 web.xmlJava 示例SpringMVC应用程序中存在什么问题,java,spring,Java,Spring,我对SpringMVC比较熟悉,我开发了一个示例helloworld应用程序,但在将一个jsp页面导航到另一个jsp页面时出错 **maven项目创建时提供的信息 **项目文件夹结构 web.xml <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>practice1</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>practice1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spring.practice1</groupId>
<artifactId>parctice1</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>practice1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
<build>
<finalName>practice1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring.version>5.2.3.RELEASE</spring.version>
<mysql.version>5.1.36</mysql.version>
<javax.version>3.1.0</javax.version>
<junit.version>3.8.1</junit.version>
<jdk.version>1.8</jdk.version>
</properties>
4.0.0
com.spring.practice1
hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Hello</title>
</head>
<body>${message}
</body>
你好
${message}
每当点击索引页面的超链接导航到hello页面时,就会出现以下错误。
eclipse控制台日志如下所示
信息:服务器启动时间为[10576]毫秒
2020年1月26日11:12:02 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告:GET/practice1/helloworld没有映射。您需要在链接的上下文路径前面加上前缀
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
...
<a href="${contextPath}/helloworld">Click here to read hello message</a>
...
更新项目文件夹结构及其工作的类路径后,请查找。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>HelloWorld</title>
</head>
<body>
<a href="helloworld">Click here to read hello message </a>
</body>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Hello</title>
</head>
<body>${message}
</body>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
...
<a href="${contextPath}/helloworld">Click here to read hello message</a>