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

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

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 create jsp page in springboot project?

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

Spring boot + Jersey, Cannot find static resources

I have configured spring boot to load Jersey as a filter.
spring.jersey.type=filter
I have set my Jersey property to allow static content:
property(ServletProperties.FILTER_FORWARD_ON_404, true);
I have read in spring boot that I can put my content inside my resources dir, under directories named 'static', 'public' folders. Yet, I can never reach my index.html page. The only way I have gotten this to work is to create a webapp dir under src/main and put my index.html file in there.
I have tried to access the page with following urls:
http://localhost:8080/app/index.html <-- only works with webapp
dir
http://localhost:8080/app/static/index.html
http://localhost:8080/index.html
I am using spring-boot-starter-jersey 1.3.2-Release and

How to import css/js in spring MVC application jsp page

I am new to spring mvc , I am creating a user registration page , there I need to put external css and import external js .
I put the script tag with src and link tag with href. But i think in Spring MVC application they will not work straight forward.
For this I added resourceservlet mapping but still it is not working
I am not able to find any way how I csn include these assets in my jsp file.
Please help me to get this one.
Regards,
Pranav
Put the CSS, JS, image files, etc., into a directory (which may contain subdirectories) in your web site, and than map the requests to that directory:
<mvc:resources mapping="/resources/**" location="/public-resources/"/>
In this example the files are in the public-resources directory, and you refer to them using /resources in the link in your JSP.
For more information see Spring docs

Loading image in Spring application

I have this kind of solution in my Spring application:
http://www.java2s.com/Code/Java/PDF-RTF/AddingPNGimagetoPdfdocument.htm
Anyhow my problem is that my picture is in different folder like WEB-INF/layout/picture.gif.
I don't get it to work. Is there any disrictions, maybe?
Move your picture to the classpath as a resource, so then you can load it to iText easily. In order to do that you should copy the image file to the directory where the classes are, so the image is packed into the JAR or alternatively is in /WEB-INF/classes directory if this is JAva webapp (war).
Factory method of com.lowagie.itext.Image takes java.net.URL as argument, so you do this:
URL imageUrl = getClass().getResource("/your/image/package/image.png");
Image image = Image.getInstance(imageUrl);
This answer assumes that you try to access the images from a web browser directly.
Images that can directly accessed by an browser have to be located outside of the WEB-INF directory.
For example in a maven project
-project/main/src
-webapp
-images <- in the same parent directory like META-INF and WEB-INF
-META-INF
-WEB-INF

Resources