Java 如何从maven项目返回网页
我正在尝试使用maven项目返回网页。这适用于html页面,但我需要JSP。当我尝试在控制台上加载JSP页面时,表示dispatcherservlet的初始化已开始,但该网页未返回到浏览器 代码如下: 主要类别:Java 如何从maven项目返回网页,java,maven,jsp,Java,Maven,Jsp,我正在尝试使用maven项目返回网页。这适用于html页面,但我需要JSP。当我尝试在控制台上加载JSP页面时,表示dispatcherservlet的初始化已开始,但该网页未返回到浏览器 代码如下: 主要类别: package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; i
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@SpringBootApplication
@Configuration
@ComponentScan(basePackages="com.example")
@EnableWebMvc
public class DemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("static/templates/");
resolver.setSuffix(".jsp");
return resolver
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
和我的控制器类:
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@RequestMapping(value="/home")
public String home(){
return "home";
}
}
如果你能提供你得到的回应,那就太好了。 您可以尝试将
@ResponseBody
添加到控制器
@Controller
public class HomeController {
@RequestMapping(value="/home")
@ResponseBody
public String home(){
return "home";
}
}
如果你能提供你得到的回应,那就太好了。 您可以尝试将
@ResponseBody
添加到控制器
@Controller
public class HomeController {
@RequestMapping(value="/home")
@ResponseBody
public String home(){
return "home";
}
}