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.
Related
Hi StackOverflow Community i need help
How to access jsp files from, folders of subfolders Spring MVC
My project structrue is
WebContent
--WEB-INF
--Admin--index.jsp
--Student--Student.jsp
--Student
--StudentRecord--StudentRecord.jsp
--Fees
--StudentFees--StudentFees.jsp
i want to put all prefix " value path in Dispatcher-servlet.xml" ...how to do please help.
exclude this answer(in controller return "WEB-INF/Admin/index" )
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.
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.
I'm migrating a Play! 1.2 web application and moving to Spring Boot + Spring MVC. Some views contain URLs to other endpoints. For example, I display the book title on the page and next to it I want to add the URL to go the book's details page (e.g. localhost/books/{id}).
In Play! 1.2 the controllers are static, and there is also a Router which can create the full URL for a method belonging to another controller (Router.getFullUrl("BookController.bookDetails", args)), but how do I achieve this with Spring MVC?
Best regards,
Cristian.
If you are trying to get the app/deployed name automatically in .jsp files to make the urls, then please make use of context path. An example below :
<c:set var="context" value="${pageContext.request.contextPath}" />
<script src="${context}/themes/js/jquery.js"></script>
From your requirement "admin.myapp.com","admin-test.myapp.com" are server names right? Something like http://admin.myapp.com/book/{bookId},http://admin-test.myapp.com/book/{bookId}. In Spring app, relative path in jsp can be accessed using pageContext.request.contextPath
I also found the UriComponentsBuilder and ServletUriComponentsBuilder. They are similar to the Play! Framework router and provide methods for building URI's, handling parameters and the query etc. We chose to annotate the controllers' methods using constants and then use the same constants with the UriComponentsBuilder to build back the path and create the request query for GET requests.
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