Reputation: 129
I'm trying to run my first Spring MVC Program on eclipse using XML configuration, I have no error markings on my directory but I get this response when I run the program. I also tried with Spring java configuration and got similar response. bug
I use eclipse Version: 2021-06 (4.20.0) and apache-tomcat-10.0.13 installed on my device, sending a request at http://localhost:8080/ returns apache-tomcat successfully installed. So far I have tried all suggestions I found online including updating maven project, maven build-clean install, cleared file cache, deleted temp folder in my root director changed workspace directory, uninstalled and reinstall apache-tomcat multiple times, cleared missing files on source directory in java build path but none of this approaches have worked. Below is a screenshot of my program (XML configuration)
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.idevelope</groupId>
<artifactId>spring-mvc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Spring MVC</name>
<description>Spring MVC example</description>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
</plugin>
</plugins>
</build>
</project>
(View Pages)
home.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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Spring MVC tutorial - Home JSP</title>
</head>
<body>
<h1>Hello World!</h1>
<h4>Message- </h4><span>${message}</span>
<form:form action="showUser" modelAttribute="user" method="post">
<tr>
<td>
<form:label path="firstName">First Name</form:label>
</td>
<td>
<form:input path="firstName" id="firstname" />
</td>
</tr>
<tr>
<td>
<form:label path="lastName">Last Name</form:label>
</td>
<td>
<form:input path="lastName" id="lastname" />
</td>
</tr>
<input type="submit" value="Submit">
</form:form>
</body>
</html>
Please I need help to fix this bug.
Upvotes: 0
Views: 2169
Reputation: 487
In my case and as i searched internet - tomcat 10 does not work. I downloaded tomcat 9 and 404 disappeared. Spring MVC 5 does not work on Tomcat 10. This is because Tomcat 10 is based on Jakarta EE 9 where package names for APIs have changed from javax.* to jakarta.*.
Upvotes: 3
Reputation: 68
Try adding tomcat jasper dependency to pom.xml
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>10.1.0-M5</version>
</dependency>
check tomcat version before adding the dependency
Upvotes: 0
Reputation: 1865
You write, you try to run your first spring program with Spring MVC. I did not dive into your details, but I would suggest two different approaches to learn and play around with Spring MVC:
When I try out new spring parts, I always start at
https://start.spring.io/
and just add my wanted dependencies (search for mvc
when pressing add button).
After defined your setting there, you can just download a working maven or a gradle example directly from the web page as a zip file. After extraction the files can be directly imported by IDE (e.g. eclipse, intelliJ, etc.)
When you are searching a good and out-of-the-box working MVC example you should look at https://spring.io/guides/gs/serving-web-content/
This works well and you can start directly without dependency problems etc.
Upvotes: 0
Reputation: 1
maybe lack *<mvc:annotation-driven/>*Annotation-driven injection (e.g. Controller, @requestMapping, etc.) results in a page always indicating that the relevant resource information cannot be accessed
Upvotes: 0