Spring MVC Controller opens wrong .jsp file - spring

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.

Related

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

Config sub-folder in Thymelaf Spring Boot

How can I configure thymeleaf to recognize view/htmls under sub-folder?
I have templates/ folder right now and all my view HTML pages are found in this single folder.
By default spring-boot searches for all files and folders under resources. So feel free to create subfolder for example under templates/.
You just have to set the folder structure to your returning view or of your fragments in html.
Just an example of a project from me:
Controller:
#GetMapping(value = "/getAnyWellBox")
public String getAnyWellBox(Model model)
//any code
return "thirdparty/booking/map/well-box";
}

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

Spring Security + Spring MVC how to integrate them properlly?

I have a working project with both frameworks doing fine
My problem is how to architect it.
I have set 3 Roles ( Admin, Operator, User), and one folder for each of them. like thid
WebContent
|___admin
|___user
|___operator
|___WEB-INF
|__jsp
in admin,user, and operator are those roles only jsps
in jsp are all public jsps.
Is this the right way to do it ?
because when I create my viewResolver it only points to Web-Inf->jsp... So I am having trouble to make my requests land on those folders.
I want to be able to put a .jsp in a folder so it would automatically be assigned to a Role.
But I would like to be able to reuse the JSPs too.
Should I create another view resolver to each of those folders ?
Should they all be inside the WEB-INF folder ?
What is the best (more used and simple) way of doing this ?
I just added the user role folders into WEB-INF and used redirect... now it's working.

Resources