JSP 起始页错误:解析模板时出错,模板可能不存在,或者任何已配置的模板解析程序都无法访问



我有一个 Spring 启动应用程序,我想在其中启动该应用程序 与"开始.jsp"页面一起使用。无法加载起始页。它位于"资源/模板"文件夹中。

<%@ 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 ;
   }
}

消息.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 文件

我已经完成了以下步骤:

在应用程序属性中添加以下内容:

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 打开构建路径中,然后添加源代码)

最新更新