Spring Boot下载jsp文件 [英] Spring boot downloading jsp file
问题描述
我正在使用Spring Boot简单应用程序来显示JSP. 但是,无需呈现JSP,而是在浏览器中下载页面. 请提出建议吗?
I am using spring boot simple application for displaying a JSP. However instead of rendering the JSP the page gets downloaded in the browser. Please suggest?
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/main/webapp文件夹,并将printReciept.jsp放入其中.
I have made the folder src/main/webapp and put printReciept.jsp in that.
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
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>
控制器受到攻击,但不是呈现JSP,而是在浏览器中下载该页面.请提出建议.
The controller is getting hit but instead of rendering the JSP it is downloading that page in browser.Please suggest.
推荐答案
我遇到了同样的错误,但是我没有把负责转换我们的jsp文件的tomcat jasper放进去,
I Got same error but i am not putting tomcat jasper who is responsible for converting our jsp files,
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.16</version>
</dependency>
只需使用tomcat根据您的春季启动时间添加tomcat-jasper
Just add tomcat-jasper according to you spring boot using tomcat
这篇关于Spring Boot下载jsp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!