无法使用spring-boot加载非常简单的JSP页面,导致404未找到
HmisApplication.class
@SpringBootApplication
public class HmisApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(HmisApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(HmisApplication.class, args);
}
}
主控制器。Java语言
@Controller
public class WelcomeController {
@RequestMapping("/")
public String home(Map<String, Object> model) {
model.put("message", "HowToDoInJava Reader !!");
return "index";
}
@RequestMapping("/next")
public String next(Map<String, Object> model) {
model.put("message", "You are in new page !!");
return "next";
}
}
应用属性
spring.profiles.active=dev,build-info
server.contextPath=/hmis
server.port=7070
spring.metrics.export.enabled=true
spring.main.banner-mode=off
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
application.message: Hello Phil
# HTTP encoding (HttpEncodingProperties)
spring.http.encoding.force-request=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"
<groupId>com.hmis</groupId>
<artifactId>hmis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>hmis</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Tomcat Embed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- To compile JSP files -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
MVC配置。Java语言
@Configuration
@EnableWebMvc
@ComponentScan
public class MvcConfiguration extends WebMvcConfigurerAdapter
{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
}
}
文件结构
├── src
├── main
│ ├── java
│ │ └── com
│ │ └── hmis
│ │ ├── HmisApplication.java
│ │ ├── MvcConfiguration.java
│ │ ├── WelcomeController.java
│ └── resources
│ └── application.properties
│ └── webapp
│ └── WEB-INF
│ └── jsp
│ └── index.jsp
│ └── next.jsp
我得到了显示如下内容的jsp页面。我正在使用IntelliJ Ultimate。
1.创建webapp、WEB-INF、jsp目录,如src-
2.放置了要在src渲染的jsp页面(login.jsp)-
下面的屏幕截图供快速参考
3.在application.properties文件中增加以下内容:
spring.mvc.view.prefix= /WEB-INF/jsp/
spring.mvc.view.suffix= .jsp
4.在pom.xml中注释了来自tomcat-embed-jasper
依赖的版本
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- <version>10.0.2</version>-->
</dependency>
我解决了一些更改后的问题pom.xml.注释出tomcat-embed-jasper
依赖项的范围
标记。
<groupId>com.hmis</groupId>
<artifactId>hmis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>hmis</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Tomcat Embed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- To compile JSP files -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我不知道如何解决这个问题 spring端:role.java 因此,如果我现在尝试inline=“javascript”: 当我运行它时,我得到这样的响应: 白标签错误页
当我运行spring boot MVC应用程序时,得到以下白标签错误页面。 白标签错误页 此应用程序没有/error的显式映射,因此您将其视为一种后退。 Wed Apr 13 15:45:59 IST 2016出现意外错误(Type=内部服务器错误,Status=500)。循环视图路径[home]:将再次发送回当前处理程序URL[/rewards/web/home]。检查您的ViewResolve
我试图创建一个spring boot starter项目。当我试着运行这个时,我遇到了这个错误。 白标签错误页面 此应用程序没有 /error的显式映射,因此您将此视为后备。 Fri Dec29 14:16:46IST 2017有一个意外的错误(type=未找到,status=404)。/ 我将jsp文件添加到src/web-inf/views中/ 已添加 Springmvc。看法前缀=/WEB-
下面是我的代码:我正在从application.properties文件swagerconfig.java获取所有值 下面是我的springboot初始值设定项: ServletInitializer.java 日志显示它已映射: 这是我得到的错误:
我坚持使用这个简单的MVC示例。当我启动应用程序并转到localhost:8080时,我得到了“白标签错误页面”,甚至我在“src/main/资源/模板”中创建了“index.html”。我还在我的索引方法上添加了@Request estMap(“/”)。我找不到问题。 : : -在"src/main/资源/模板"下:
我尝试使用spring boot 2.2和thymeleaf进行表单验证,如文档示例所示(https://spring.io/guides/gs/validating-form-input/)但当提交错误的值时,我有一个白色标签错误页面,而我应该在表单视图中绑定这些错误。如何解决这个问题? 我的控制器操作代码: 和视图: 堆栈跟踪是: Whiteblabel错误页面为: 典型情况下,name字段的