How can I create jsp page in springboot project? - spring-boot

I have spring boot project in IntelliJ IDEA by maven and when I want create jsp page like name"index.jsp" it being disable and not active as jsp page please help.
How can I solve that problem?

inside /src/main/resources/application.properties (if you dont have this file craete it)
append the following:
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
please note your jsp must be inside WEB-INFF/jsp/ folder, if you want it in another folder just change the value of this property

Related

Spring MVC Controller opens wrong .jsp file

my project structure looks like below:
The issue is when I return in HomeController .jsp file named "home" and run this project on Tomcat server I receive website but not from home.jsp, but index.jsp (1 screenshot).
My question is is there any file where starting .jsp file is defined as a launcher ? If not so why index.jsp always launches while Controller Class returns a different file ?
Solved
I have created a new project (Maven project + Web archetype) and works fine. I assume that a problem was with location of web folder. Now I have it inside src folder unlike in previous structure.

how can i set prefix path for thymeleaf in spring boot

How can I set the prefix path(set the new directory) to render the HTML page?
I have a spring boot application. I am using version 2.1.7.
I am set a new path for view page.
Add the following line in Application.properties
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/views/ #this is the main
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.main.allow-bean-definition-overriding=true
You can use basic setup or by overriding a property in application.properties to give your own customise page.
A prefix that gets prepended to view names when building a URL.
spring.thymeleaf.prefix=classpath:/config/templates/

How does spring resolve .jsp page without controller mapping

I'm trying to understand the following issue. When I type url http://localhost:8076/demoproject_war/test.jsp spring is able to load test.jsp page. Here is the pic of my directory structure.
My question is how spring loads ./test.jsp even though I don't have any mappings in my controller class for ./test.jsp . Does not this request go to controller to check the mappings?
Spring does not load this JSP when you go to that URL. You're navigating directly to the JSP. It is considered a bad practice as you're not controlling the execution in this case. You should put the JSPs inside a webapp/WEB-INF directory. Then, the won't be accessible directly.

How to set SameSite:Strict for all cookies in spring 5

Is there anyone can tell me how to add SameSite:Strict to all cookies created in spring 5.1? I know in spring 4, this attribute was not supported. But since Spring 5.1, It can be as declare at here!
But I don't know how to apply this to my project? Where should I put it? Please help me! Thanks!
I cannot add SameSite attribute to my project using Spring because Object javax.servlet.http.Cookie hasn't supported this attribute. But I could custom cookie header in Apache tomcat (version 9.0.11) by add the following line to conf/context.xml:
<Context allowCasualMultipartParsing="true">
...
<CookieProcessor className="org.apache.tomcat.custom.coyote.TomcatCoyoteCustomer"/>
</Context>
And then create a project "CustomCookieProcessor" with TomcatCoyoteCustomer class that extends Rfc6265CookieProcessor class, override method generateHeader and append "SameSite:Strict" to cookie header. Finally, I copy jar file of "CustomCookieProcessor" project to folder lib of Tomcat. You can read more detail about CookieProcessor of Apache Tomcat at here!

Can we provide JSP pages from sec/main/resources source folder

I am trying to provide JSP pages under sec/main/resources instead of webapp folder and configured source folder in application.properties as below but not working, let me know can we do this and how
spring.mvc.view.prefix=/src/main/resources
spring.mvc.view.suffix=.jsp

Resources