#spring #spring-boot #jsp #jersey #apache-tiles
#spring #spring-boot #jsp #jersey #apache-tiles
Вопрос:
Я борюсь с этой проблемой уже довольно давно.
В одном из моих старых проектов я использовал такие плитки Apache:
контроллер
@Controller public class PageController { @RequestMapping("/about") String about() { return "app.about"; } }
POM.XML
lt;dependencygt; lt;groupIdgt;org.apache.tileslt;/groupIdgt; lt;artifactIdgt;tiles-corelt;/artifactIdgt; lt;versiongt;${tiles.version}lt;/versiongt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.apache.tileslt;/groupIdgt; lt;artifactIdgt;tiles-jsplt;/artifactIdgt; lt;versiongt;${tiles.version}lt;/versiongt; lt;/dependencygt;
Основной Класс
@EnableAsync @SpringBootApplication @EnableGlobalMethodSecurity(securedEnabled=true, prePostEnabled=true) public class App extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(App.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(App.class); } @Bean public TilesConfigurer tilesConfigurer() { TilesConfigurer tilesConfigurer = new TilesConfigurer(); String[] defs = {"/WEB-INF/tiles.xml"}; tilesConfigurer.setDefinitions(defs); return tilesConfigurer; } @Bean public UrlBasedViewResolver tilesViewResolver() { UrlBasedViewResolver tilesViewResolver = new UrlBasedViewResolver(); tilesViewResolver.setViewClass(TilesView.class); return tilesViewResolver; } } }
TILES.XML
lt;?xml version="1.0" encoding="ISO-8859-1" ?gt; lt;!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"gt; lt;tiles-definitionsgt; lt;definition name="app.about" extends="app.default"gt; lt;put-attribute name="content" value="/WEB-INF/tiles/about.jsp" /gt; lt;/definitiongt; lt;/tiles-definitionsgt;
And about.jsp
lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%gt; This is the about page.
And this works perfectly, when I navigate to localhost:8080/about I’m getting this message: «This is the about page.»
However, my problem is that I cannot use apache tiles on my other project where I’m using Jersey annotations (@GET, @Produces, @Path instead of @RequestMapping from above’s case)
Not working:
@Path("/test") @Service @Singleton public class LogService { @GET @Produces("text/plain") @Path("/logs") public String showLogsInBrowser() { return "app.logs"; } }
When I navigate to: http://localhost:8080/test/logs I’m getting this «app.logs» text on my page instead of text that is written in my logs.jsp page.
I tried to remove this annotation: @Produces(«text/plain») but still I’m getting actual string instead of jsp page:
tiles.xml
lt;?xml version="1.0" encoding="ISO-8859-1"?gt; lt;!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"gt; lt;tiles-definitionsgt; lt;definition name="app.logs"gt; lt;put-attribute name="content" value="/WEB-INF/tiles/logs.jsp"/gt; lt;/definitiongt; lt;/tiles-definitionsgt;
logs.jsp
lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%gt; LOG FILE TILES!
So as I said, on the first project, everything works as expected, and on the second project, only difference is with these annotations so I figured that is the problem, however I don’t know how to fix it. When I try to use @RequestMapping(«/logs») instead of these 3 @GET @Produces(«text/plain») @Path(«/logs») I get whitelabel error page and when I put back these 3 annotations (or only two, @GET and @PATH) I’m getting app.logs as a string written on the page instead of JSP page that I’m trying to call.
I’m out of ideas, so I hope that you know what is the problem. Thanks!