java - spring boot load jsp as txt? -
i use spring boot simple web page. here codes:
src/main/java/application.java
@springbootapplication public class application { public static void main(string[] args) { springapplication.run(application.class, args); } }
src/mian/java/config.java
@configuration @enablewebmvc public class config extends webmvcconfigureradapter { @override public void configuredefaultservlethandling(defaultservlethandlerconfigurer configurer) { configurer.enable(); } @bean public internalresourceviewresolver viewresolver() { internalresourceviewresolver resolver = new internalresourceviewresolver(); resolver.setprefix("web-inf/views/"); resolver.setsuffix(".jsp"); return resolver; } }
src/main/java/testcontroller.java
@controller public class testcontroller { string name = "peter!"; @requestmapping("/test") public string admin(modelandview mv) { system.out.println("in controller"); mv.addobject("name", name); return "test"; } }
src/main/webapp/web-inf/views/test.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>just test</title> </head> <body> ${name} </body> </html>
i start project application.java, , put http://localhost:8080/test in browser, browser show source code of test.jsp. seems spring boot treat jsp txt file... how fix it?
add dependency pom.xml
<dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-jasper</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <scope>provided</scope> </dependency>
Comments
Post a Comment