javascript - CSS and JS file loactions in a maven project - Stack Overflow

I a currently working on a maven project on eclipse , my HTML , css , js and jsp files are under webapp

I a currently working on a maven project on eclipse , my HTML , css , js and jsp files are under

webapp
    |
     WEB-INF
           |
            css/style.css
            js/myjs.js
            index.jsp
            index1.html

My webapp cannot seem to access the CSS and JS, I keep getting the following error in Chrome for my CSS, img, and JS files:

GET "URL....................css" 404 (Not Found)                      friend:5

I have seen a lot of questions related to this, but none of the solution seems to work. Any help would be appreciated!

I a currently working on a maven project on eclipse , my HTML , css , js and jsp files are under

webapp
    |
     WEB-INF
           |
            css/style.css
            js/myjs.js
            index.jsp
            index1.html

My webapp cannot seem to access the CSS and JS, I keep getting the following error in Chrome for my CSS, img, and JS files:

GET "URL....................css" 404 (Not Found)                      friend:5

I have seen a lot of questions related to this, but none of the solution seems to work. Any help would be appreciated!

Share Improve this question edited Jul 20, 2012 at 0:33 Derek 朕會功夫 94.5k45 gold badges198 silver badges253 bronze badges asked Jul 20, 2012 at 0:25 Rahul KumarRahul Kumar 3993 gold badges8 silver badges26 bronze badges 2
  • The css and js files definitely don't go in the WEB-INF folder. If you're using tomcat, there should be a WebContent folder and the js, css and jsp files go there. Try moving all your files to webapp/ – icanc Commented Jul 20, 2012 at 0:41
  • @Rahul - Hey I am facing the same issue, I moved all the js and css files to webapp folder and I am referencing the js file in jsp in following manner: '<script type="text/javascript" src="/js/foo/bar.js">' . But I still get the 404 Not found....Can you tell me how you are referencing the js file in jsp? – aces. Commented Feb 14, 2013 at 17:07
Add a ment  | 

2 Answers 2

Reset to default 3

point 1: Move your web content files (html/jsp/js/css) out of web-inf, create respective folders directly under webapp.

point 2: pls share the code snippet of how you are referring to the image or js or css from your HTML/JSP page.

E.g. In the below folder structure the image/css/js resources are referred in html/jsp as

 webapp
   |
   |__ pages
   |    |___ index.jsp
   |    |___ index.html
   |
   |__ css
   |    |___ style.css
   |    
   |__ js
   |    |___ myjs.js


That error is basically saying "the file is not there!". The thing is, whether the files are there or not has nothing to do with Maven (or Tomcat or whatever); it's all controlled by your webserver (which is likely Apache). Assuming it is Apache, you'll want to look at your config to see what the DocumentRoot is set to, as that's where where static files are served from (although Apache config can get more plex than that so it really depends on your particulars).

The general thing to understand though is that just throwing things in WEB-INF doesn't inherently expose them to the world: you need to have the files exposed via Apache.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744955662a4603178.html

相关推荐

  • javascript - CSS and JS file loactions in a maven project - Stack Overflow

    I a currently working on a maven project on eclipse , my HTML , css , js and jsp files are under webapp

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信