我有一个Spring Boot应用程序,我想在其中启动该应用程序 与Start.jsp页面。 “开始”页面无法加载。它在resources / templates文件夹中。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form id="messageForm" action="sendMessage" method="post">
<div>Personal Information</div>
<div>
<!-- Name attribute of fields is the same as the corresponding Java class-->
<label>Name</label> <input name="name" value="" type="text">
</div>
<div>Message Details</div>
<div>
<label>To number</label> <input name="toNumber" value="" type="text">
<label>From number</label> <input name="fromNumber" value="" type="text">
<label>Message Body</label> <input name="messageBody" value="" type="text">
</div>
<div>
<button id="submitButton" type="submit">Send Message</button>
</form>
</body>
</html>
控制器看起来像:
package com.smsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class WebController {
@RequestMapping(value = "/")
public String index() {
return "Start";
}
@RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
public void sendMessage(Message message){
//code for controller
return ;
}
}
Message.java是一个实体类,其名称与表单中的字段相同。
预期结果应该是一种表格,我可以在其中放置数据并提交
但是我得到的是错误以下信息:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jan 20 13:41:59 EST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [Start], template might not exist or might not be accessible by any of the configured Template Resolvers
另外,当我使用html文件时,它可以工作,但不适用于jsp文件
答案 0 :(得分:0)
我已完成以下步骤:
在application.properties中添加以下内容:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
在pom.xml中添加了以下代码:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
确保结构/ WEB-INF / jsp /具有我的jsp文件并添加到我的类路径中(在Eclipse中打开构建路径,然后添加源)