내가하려는 것은 JSP 페이지를 사용하여 간단한 Hello world 메시지를 인쇄하는 것입니다.하지만 시도하면 아래와 같이 404 not found 오류가 발생합니다.
이것은 위의 다이어그램에 표시된 내 프로젝트 구조입니다.
package com.example.MailSender;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.example.MailSender","com.example.MailSender.Controller"})
public class MailSenderApplication {
public static void main(String[] args) {
SpringApplication.run(MailSenderApplication.class, args);
}
}
주요 애플리케이션 클래스는 위와 같습니다.
package com.example.MailSender.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/hello")
public class SimpleController {
@GetMapping("/world")
public String sample()
{
return "sample";
}
}
내가 코딩 한 매우 간단한 컨트롤러가 위에 나와 있습니다.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Hello world</title>
</head>
<body>
<h1>Basic config successful!!!</h1>
<h2>Hello World</h2>
</body>
</html>
메시지를 표시하는 매우 간단한 JSP 페이지
server.port=9090
spring.mvc.view.prefix=/src/main/resources/static
spring.mvc.view.suffix=.jsp
이것은 application.properties 파일입니다.
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>MailSender</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MailSender</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
pom.xml 파일
내가 어디로 잘못 가고 있는지 이해할 수 없습니다. 도와주세요. 왜 404 오류가 발생합니까? 나는 http : // localhost : 9090 / hello / world가 유효한 URL이라고 믿습니다.
두 가지 문제가 있습니다.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
/src/main/resources/static
같은 정적 파일을 보유하는 것을 의미 html
하고css
src/webapp/WEB-INF/jsp
spring.mvc.view.prefix=/WEB-INF/jsp/
https://hellokoding.com/spring-boot-hello-world-example-with-jsp/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다