Spring Boot Request mapping not loading static resources - java

I have a spring boot application where I serve some static jsp pages stored in directory src/main/webapp which includes some javascript references stored under directory "src/main/resources/static". When I do the requestmapping for "/somepath" then it successfully returns view that has javascript references in static resources folder such as "src/main/resources/static/lib/script.js"
But the problem that I'm facing right now is when I do the #requestmapping to "/sompath/xyz" then I get HTTP 404 error. When I inspected the page source then I found out that the page was searching for static folder in this path "/somepath/lib/script.js" that is "/somepath" is getting prefixed to the default resources location. Is there any way that I could map these URIs such that no matter how many "/path/" are there, it will look for resources under the "/static/" folder only and not like "/static/path"
Any help is appreciated. I apologise for my problem structure as I'm a beginner and I'm still learning to put all these things in better perspective. Thanks in advance.

I have same problem I found the way but its half solution.
first
use RequestMapping path depth just one like 'spring'
It is work well every situation.
second
use RequestMapping path depth tow like 'spring/xyz' and <link src="../some.css"/>
last
use depth 3 'spring/xyz/123' and <link src="../../some.css"/>
This all is messed up but it is working.
So I open the question on stack overflow again here please anyone come and check this and leave some idea thanks~!

Related

How to debug org.thymeleaf.exceptions.TemplateInputException?

I have a new project and it's my first time using spring MVC and Thymeleaf.
The error message that I'm getting seems obvious:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
I have googled a lot and saw many people with similar issues. However, none of the solutions helped me find out why my setup does not work.
Instead of classpath:/templates I have also tried variations like templates and /templates
some questions:
What is the "basedir" from which the relative path is being looked for?
Is it possible to run spring in debug to see how these kind of configurations are set? i.e. call when I call localhost:8080 and there's a breakpoint somewhere: would it be possible to see how the file index.html is being looked for?
edit On line 23 in the document on the right (BetterCommuteApplication.java) you can see that Intellij is able to resolve the reference to my template file.
This screenshot shows my configuration and I think it should suffice as enough information to get the answer.
Thank you for your time! :-)
ugh, I tried to combine Spring boot with thymeleaf manually here.
(I'm used to developing back-ends ^^")
This doesn't make much sense as initialising spring MVC does this right out of the box.
The solution was to init this as springMVC, use #Controller instead of #Restcontroller because I want the class to be handled as MVC class... and the return could be as simple as return 'index' (because my html file in the default location is called index.html)
basically I would have known, if I'd simply followed the tutorial on SpringMVC... but hey, why would anyone RTFM? :-)
so it looks like this:

Remove .jsp ending with tomcat and nginx

I would like to www.example.com/test.jsp as www.example.com/test.
URL rewriting and so on should be too slow. Are there any alternatives? For example, maybe using the jsp files or only servlets when they work with java?
I'm looking for good solution in terms of performance and for the google ranking. The website has 200 pages and grows, so I can't do it manually for every page.
I googled but I didn't find a good answer.
Can't believe you wrote a website with 200+ separate jsp pages. Consider changing site architecture, for example if you have online store with many pages of the same type, you could write only one jsp content page as template and use RESTful architecture to build real page content.
In the nginx configuration, you can make a rewrite of the url when you do the proxy pass

HTTP Status 404 Eclipse Tomcat 7

I am getting Error 404 when trying to run my application.
Tomcat server, start and synchronized. Dynamic module version is 2.5.
Previously I used dynamic module version 3.o but it didn't work. I read in
one of the posts that better is to use 2.5. so I created new project and
still get this 4044 error. It is technical error I think.
I needed to create index.jsp WebContent->New->JSP file and it will place it in the right spot. Now I am able to see my index page.
The problem was that I created index.jsp file WEB-INF->New->JSP file. You can see it above in my post.
Here I place the image where you can see image.jsp is place in different spot. You can see small difference.
That's why I asked you to create a test dynamic project to compare. I think when you created that new project you placed index.html under WebContent correctly. So you couldn't figure out with that example.
Also you can place your jsp inside WEB-INF. That's a recommended way too to keep it safe . I mean if the file is inside WebContent a Web user can navigate to the location and access it. But if it is inside WEB-INF the access is controlled by your web.xml.
So in your former case just give the relative path .ie /WEB-INF/page.jsp

jsp, can't find source of css property

This may be a tricky question because I can't give much detail,
I'm working of legacy code on a big project (in jsp) and I came across a "styleid = product".
It changes quite a lot of things when I remove it, but I can't seem to find it in any of the CSS files, there are properties like "tdproduct" and "thproduct" but I can't seem to find any connection.
Can anyone give me an indication of other places I might need to look for this (except .css files).
thanks in advance
Can you load the page in firefox/chrome browser?
If so you can see the generated source code.
Since JSP is a server side technology that generates some dynamic content, its also possible that the CSS will be also generated dynamically.
Theoretically it can be JSP itself, the CSS and even Java Script :)
Good luck!
Hope this helps
css are dynamically loaded when your page is loaded. your style classes can also be defined in the jsp that you are including in the parent jsp.
open the page in firefox and use firebug to view the styles loaded. You can locate where your style is loading from.

Call jsp page from autocompete function in liferay

$(function() {
$("#ac1").autocomplete('getdata.jsp');
}
I'm calling that page in liferay6..
so, What sort of changes I will have to make in portlet.xml and another file ..
I'm getting this error....
http://localhost:8080/web/guest/getdata.jsp?q=abc 404 Not Found
(This error is coming in Firebug not in UI)
Thanks in Advance,
Mayur Patel
First of all, if you are using a portlet specific resource as the data, you should probably be using portlet:resourceURL or liferay-portlet:resourceURL instead of a static address to the file getdata.jsp. ResourceURLs create fully qualified URLs that target your own portlet. The resource served are supposed to be content fragments instead of full blown pages. That way they are especially suitable for AJAX-calls.
Where is the getdata.jsp file located? You could define the full path to the file i.e. /my-service/getdata.jsp instead of relying on the relative address that points to the /web/guest url-mapping. That way you can be sure that the file is found provided that you are not going to share the portlet with others that might not install the portlet the same way as you have done.

Categories

Resources