gpt4 book ai didi

java - 问题错误 404 jsp not find 项目 spring boot 和 jboss

转载 作者:行者123 更新时间:2023-12-02 09:04:16 25 4
gpt4 key购买 nike

我的jsp映射有问题,错误404。我尝试使用客户端-服务器Jboss(我没有选择)。我已经尝试使用 springbootapplication 或 jboss 启动。当我开始使用 springbootapplication 应用程序不起作用但它启动并且 jboss 我可以访问在线页面 8080 主页 jboss

Controller 公式

@Controller
public class RequestController {
Logger logger = Logger.getLogger("test log 1");

@Autowired
RddRepository rddRepository;

@GetMapping("/formulaire")
public String showFormulaire(Model model) {
model.addAttribute("formulaire", new Formulaire());
logger.info("test appel jsp requeteform");
return "formulaire";
}


@PostMapping("/requeteFormulaire")
public String save(@Valid Formulaire formulaire, BindingResult bindingResult) {
RddRepository.save(formulaire);
return "requeteFormulaire";
}

公式.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Formulaire Requete</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="col-md-offset-2 col-md-7">
<h2 class="text-center">Formulaire jeu test</h2>
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Formulaire</div>
</div>
<div class="panel-body">
<form:form action="/save" Class="form-horizontal">



<div class="form-group">
<label for="identifiant" class="col-md-3 control-label">code compte</label>
<div class="col-md-9">
<form:input path="identifiant" maxlength="9" Class="form-control" />
</div>
</div>


<div class="form-group">
<!-- Button -->
<div class="col-md-offset-3 col-md-9">
<form:button type="submit" value="Save" Class="btn btn-primary">Creer</form:button>
</div>
</div>
</form:form>
</div>
</div>
</div>
</div>
</body>
</html>

应用程序属性

server.port=8080
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
    <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</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>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
@SpringBootApplication
public class RequeteBddJeuTestApplication extends SpringBootServletInitializer {




@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RequeteBddJeuTestApplication.class);
}

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

}

最佳答案

直接使用 .jsp 文件名更改返回语句。

    return "formulaire";

return "requeteFormulaire";

Sprint MVC 将自动查找属性文件中给定的前缀/后缀的路径。

关于java - 问题错误 404 jsp not find 项目 spring boot 和 jboss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59946178/

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