私は、JSPを表示するためのスプリングブートのシンプルなアプリケーションを使用しています。 しかし、JSPをレンダリングする代わりに、ページがブラウザにダウンロードされます。 お勧めしますか?jspファイルをダウンロードするスプリングブート
application.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tcadmin?zeroDateTimeBehavior=convertToNull
spring.datasource.username=tcuser
spring.datasource.password=tcuserpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
server.port=9090
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
server.context-path=/internal
spring.mvc.view.prefix:/
spring.mvc.view.suffix:.jsp
私は、フォルダのsrc /メイン/ Webアプリケーションを作って、その中でprintReciept.jspを入れています。
のpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.a2b</groupId>
<artifactId>A2BInternalModules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>A2BInternalModules</name>
<description>Sitemap Generator for A2B</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.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>
<!-- Tomcat Embed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>required</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</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-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
PrintRecieptController.java
@RequestMapping(value = "/PrinReciept", method = RequestMethod.GET)
public String welcome(Model model) {
model.addAttribute("message", "Hello World !!!");
return "printReciept";
}
printReciept.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>
Print Receipt
</body>
</html>
コントローラがヒット代わりにJをレンダリングなっていますSPはブラウザでそのページをダウンロードしています。お勧めします。
JSPファイルの場所を指定することはできますか?WEB-INF内か、WEB-INF内の任意のフォルダ内ですか? – Yogi
webappフォルダ内です。私もWEB-INFフォルダに何らかの形でコピーを持っていますが、それはページをダウンロードします – Jeets