gpt4 book ai didi

java - 通过本地主机加载html文件时,图像未出现(使用Java Gradle启动应用程序)

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

当我使用Gradle或Maven构建一个简单的MVC应用程序时,如果我在localhost:8080 /上打开任何页面,似乎没有图像显示。但是,如果我只从目录中打开一个html文件,则所有图像都会出现。我正在使用Ubuntu,但可以使用该文件的权限没有问题(chmod 644'File_Directory')
build.gradle:

plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}

test {
useJUnitPlatform()
}
Controller :
package com.example.website;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class WebController {

@GetMapping
public String starter() {
return "starter";
}

}
应用:
package com.example.website;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WebApp{

public static void main(String[] args) {
SpringApplication.run(WebApp.class, args);
}

}
HTML文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>There needs to be an image</div> <br>
<img src="starter.png"/>
</body>
</html>
That's how it appears in the browser

最佳答案

尝试将完整的目录路径放在src中,例如:

 <img src="C:\user\starter.png"/>

关于java - 通过本地主机加载html文件时,图像未出现(使用Java Gradle启动应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64483889/

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