• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classic Problem: JSP cannot find css and images

 
Moe Ba
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I have the classical problem described in the post title. In my jsp, I am trying to look for the css using this:

<style type = "text/css">@import url(WebContent/css/adminstyle.css);
</style>

In order to help me diagnose the problem, I am trying to print on the jsp itself the value of what the above statement is resolving the url to. How can I get it
to print the value of:

@import url(WebContent/css/adminstyle.css)

I want to know what url the above statement in resulting in after it is evaluated.
ques1.png
[Thumbnail for ques1.png]
ques2.png
[Thumbnail for ques2.png]
ques3.png
[Thumbnail for ques3.png]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JspFaq for info on properly forming resource URLs.
 
Moe Ba
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I'll check out the FAQ. I've attached some screenshots to show my problem areas. I've tried so many different URL combinations that my head is spinning now. I even tried the JSTL c:url method. No luck getting my Jsp to see my resources(i.e. css, and images folder).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Screenshots are not useful. They are too fuzzy to read and cannot be searched. Please post code as text and UseCodeTags.

Also, please avoid editing your post after someone has responded. Continuing to do that will not make you any friends.

What would be most helpful is the code where you reference the resources, and (precisely) where the resources are in your filer hierarchy. The <c:url> tag will do the right thing if you feed it the correct path.
 
Moe Ba
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear, thanks for the advice. I will follow it. Sorry about the screenshots. Im a newbie to the forums and to Java EE in general. I was stuck on this problem for 8 hours between 2 days and googled my heart out. In the end, it was the knowledge on the JSP Faq page that led me to the solution. So, thank you thank you thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it worked out. Care to post what the problem was?
 
Moe Ba
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was that my jsp couldn't find my css and image resources because I was routing my static resource queries to a path one directory deeper than I should have been. This is because I was trying to find the css and images from the "jsp's perspective" whereas the guidance I received on the jsp faq advised me that one should think from the "servlet's" perspective. So, I made my routing paths in the Spring configuration file shallower by one level. There was also some confusion regarding what directory the "servlet lives in". I thought the servlet behaves as if the application context "lives in" the root directory of the project, but it helped me more to think that it "lives in" the WebContent directory of the project (the Eclipse project). I don't know if any of this makes sense. I barely just learned it so I dare not try to profess it beyond what I saw. Overall like I said I had been stuck on this 8 hours between two different days, I tried to type the URLs and routing paths a million different ways. It was very educational for me. And one solved, rewarding.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moe Ba wrote:There was also some confusion regarding what directory the "servlet lives in". I thought the servlet behaves as if the application context "lives in" the root directory of the project, but it helped me more to think that it "lives in" the WebContent directory of the project (the Eclipse project).

Actually, it's best to understand the the servlet "lives" nowhere. That's why the JspFaq states to always use server-realtive addressing which makes no assumptions about where the servlet "lives".
 
Moe Ba
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, I read that in many places and it is the best approach. I haven't quite figured out the proper notation/syntax to practice this approach but I do realize that is the ultimate solution as it check application context and uses that no matter what it changes to across deployments. Im just glad I have at least one solution though perhaps not the best one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!