当前位置: 首页 > 知识库问答 >
问题:

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

岳风畔
2023-03-14
<%@ 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 ;
   }
}

但我得到的是下面的错误:

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文件

共有1个答案

宰父子安
2023-03-14

我已经完成了以下步骤:

在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>
 类似资料: