我试图使一个网站来托管我的一些个人摄影.我已经购买了使用ubuntu访问VPS.我的网站使用Sping Boot 与MySQL数据库和使用JSP.我试图让我的网站使用Tomcat服务器工作.
编辑:我忘了说,这个项目在我的M2 Macbook上用tomcat运行得很好,遵循同样的过程。
当我尝试在 VPSip:8080/service访问我的网站时,我得到这个错误:
HTTP Status 404 - Not Found Type Status Report Message请求的资源[/service/]不可用描述源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。
当我访问 VPSip:8080/时,Tomcat工作正常。
我试着改变我的MainController类,让它有一个/service的Map,以前它只是“/",这没有帮助。
主控制器代码:
package com.example.photographygallerysite.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MainController {
@RequestMapping("/service")
public String start() {
return "start";
}
}
字符串
start引用start.jsp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Photography by Oliver Johnson</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: rgb(255, 253, 247);
margin: 0;
padding: 0;
text-align: center;
}
h1 {
color: #333;
margin-top: 50px;
font-family: 'Corben', Georgia, Times, serif;
color: rgb(38, 24, 24);
}
a {
display: inline-block;
padding: 10px 20px;
margin-top: 20px;
background-color: rgb(38, 24, 24);
color: #fff;
text-decoration: none;
border-radius: 2px;
transition: background-color 0.3s;
font-family: 'Nobile', Helvetica, Arial, sans-serif;
}
a:hover {
background-color: rgba(66, 66, 66, 0.55);
}
.slideshow-container {
max-width: 750px;
margin: auto;
position: relative;
}
.mySlides {
display: none;
width: 100%;
animation: fade 7s linear; /* Adjust the duration as needed */
}
@keyframes fade {
0%, 5% {
opacity: 0;
}
5%, 95% {
opacity: 1;
}
99%, 100% {
opacity: 0;
}
}
.w3-badge {
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s;
}
.w3-badge-active {
background-color: #4285f4;
}
/* Content separator styling */
.separator {
border-top: 2px solid #ccc;
margin: 20px auto;
width: 57%;
opacity: 50%;
}
</style>
</head>
<body>
<h1>Photography by Oliver Johnson</h1>
<div class="separator"></div>
<div class="slideshow-container w3-content w3-section">
<div class="mySlides w3-animate-fading">
<img src="http://ip:8080/images/firstImg.jpg" style="width:100%">
</div>
<div class="mySlides w3-animate-fading">
<img src="http://ip:8080/images/DSC_0393.JPG" style="width:100%">
</div>
<div class="mySlides w3-animate-fading">
<img src="http://ip:8080/images/DSC_0348.jpg" style="width:100%">
</div>
<div class="mySlides w3-animate-fading">
<img src="http://ip:8080/images/DSC_0383.jpg" style="width:100%">
</div>
</div>
<div class="separator"></div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var slides = document.getElementsByClassName("mySlides");
for (var i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
myIndex++;
if (myIndex > slides.length) {
myIndex = 1;
}
slides[myIndex - 1].style.display = "block";
setTimeout(carousel, 7000); // Adjust the timeout to match the animation duration
}
</script>
<a href="http://ip:8080/displayAll">See all pictures</a>
</body>
</html>
型
图片库网站申请代码
package com.example.photographygallerysite;
import com.example.photographygallerysite.Model.Image;
import com.example.photographygallerysite.repo.ImageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class PhotographyGallerySiteApplication extends SpringBootServletInitializer implements CommandLineRunner {
@Autowired
private ImageRepository repo;
public static void main(String[] args) {
SpringApplication.run(PhotographyGallerySiteApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
Image firstImg = new Image();
firstImg.setFilename("firstImg.jpg");
firstImg.setLocation("Hartlepool");
firstImg.setCamera("Old Nikon");
repo.save(firstImg);
Image DSC_0393 = new Image();
DSC_0393.setFilename("DSC_0393.JPG");
DSC_0393.setLocation("Hartlepool");
DSC_0393.setCamera("Old Nikon");
repo.save(DSC_0393);
Image DSC_0323 = new Image();
DSC_0323.setFilename("DSC_0323.jpg");
DSC_0323.setLocation("Hartlepool");
DSC_0323.setCamera("Old Nikon");
repo.save(DSC_0323);
Image DSC_0332 = new Image();
DSC_0332.setFilename("DSC_0332.jpg");
DSC_0332.setLocation("Hartlepool");
DSC_0332.setCamera("Old Nikon");
repo.save(DSC_0332);
Image DSC_0348 = new Image();
DSC_0348.setFilename("DSC_0348.jpg");
DSC_0348.setLocation("Hartlepool");
DSC_0348.setCamera("Old Nikon");
repo.save(DSC_0348);
Image DSC_0368 = new Image();
DSC_0368.setFilename("DSC_0368.jpg");
DSC_0368.setLocation("Hartlepool");
DSC_0368.setCamera("Old Nikon");
repo.save(DSC_0368);
Image DSC_0383 = new Image();
DSC_0383.setFilename("DSC_0383.jpg");
DSC_0383.setLocation("Hartlepool");
DSC_0383.setCamera("Old Nikon");
repo.save(DSC_0383);
Image DSC_0389 = new Image();
DSC_0389.setFilename("DSC_0389.jpg");
DSC_0389.setLocation("Hartlepool");
DSC_0389.setCamera("Old Nikon");
repo.save(DSC_0389);
}
}
型
1条答案
按热度按时间sh7euo9m1#
尝试使用Sping Boot REST API的正确指南,现在我们很少使用JSP与Sping Boot 。
尝试使用一些配置并尝试发布您的
application.properties
如果不存在,请添加此行
spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
在
pom.xml
中添加tomcat-embed-jasper
字符串