<%@ 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文件
我已经完成了以下步骤:
在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>
我已经配置了Spring-Servlet: 我的瓷砖定义是: 这会给我以下错误吗: 它工作得很好。 所以问题是Thymeleaf能接受我的文件夹结构吗?如果是,怎么做?
现在我得到了另一个错误: 有人能帮我解释为什么我必须依赖thymleaf来提供html内容,为什么我会得到这个错误。
第一次发帖时,请纠正我的错误。虽然我没有偏离文件夹结构的默认映射,但我认为我应该在设置中添加。 每当我请求/home映射时,就会得到一个TemplateInputException HomeController类:
我使用mvc+java HttpServlet+Thymeleaf模板,但它是错误的。文件home.html已经存在。 我的代码如下: 与Freemarker我使用类似,它做得很好。 非常感谢
我正在学习Spring Boot、Thymeleaf和Spring Data JPA。我为自己创建了一个示例项目,在那里我可以学习所有这些东西。我在这里不问很多问题,因为通常这是一些愚蠢的错误,我对此感到厌恶。然而,我被这一个错误卡住了,我别无选择。 这是我的项目结构:项目结构 这是我的控制器: 整个应用程序可以在这里看到。我还得到警告:找不到模板位置:classpath:/templates/(
pom文件: 当我尝试打开localhost:8080/users页面时 Whitelabel错误页面此应用程序没有针对/Error的显式映射,因此您将其视为一种后退。 我不知道如何添加页眉和页脚