eclipse+springboot+maven访问jsp页面,详细步骤图解!!!(源码)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MadCode2222222222222/article/details/79063753

项目结构:


运行效果图:


步骤:


新建maven工程:



解决项目报错:




配置pom.xml


<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.polaris</groupId>
  <artifactId>springboot_demo</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springboot_demo Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <!-- Spring Boot父依赖 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.3.4.RELEASE</version>
	</parent>


	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>


		<!-- Spring Boot web依赖 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<!-- Spring Boot 热部署 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>


		<!-- tomcat的支持. -->

		<dependency>

			<groupId>org.springframework.boot</groupId>

			<artifactId>spring-boot-starter-tomcat</artifactId>

			<scope>provided</scope>

		</dependency>

		<!-- 访问JSP页面必须配置 -->

		<dependency>

			<groupId>org.apache.tomcat.embed</groupId>

			<artifactId>tomcat-embed-jasper</artifactId>

			<scope>provided</scope>

		</dependency>


	</dependencies>
	<build>
		<finalName>maven_springboot_demo1</finalName>

		<plugins>

			<!--springframework插件配置 -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin </artifactId>
			</plugin>
		</plugins>
	</build>
</project>

更新项目解决项目报错:

项目上右键--maven--update project

新建配置文件

application.properties


application.properties文件内容:

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

WEB-INF下新建jsp文件夹,新建hello.jsp文件


hello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
你好,SpringBoot!!!
</body>
</html>

在项目上新建MyController.java文件

内容:

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MyController {
	@RequestMapping("/")
	public String start() {

		return "hello";

	}

}

在项目上新建启动类App.java

内容:

package com.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@EnableAutoConfiguration
@ComponentScan(value = {"com.controller"}) 
public class App {

	public static void main(String[] args) {

		SpringApplication.run(App.class, args);

	}

}

运行:

在App.java上右键run as --java application

运行结果:




源码CSDN下载地址:


点击打开链接



猜你喜欢

转载自blog.csdn.net/MadCode2222222222222/article/details/79063753