0

I mapped the js and css like below mention mapping

`<servlet-mapping>
 <servlet-name>default</servlet-name>
 <url-pattern>*.css</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
 <servlet-name>default</servlet-name>
 <url-pattern>*.js</url-pattern>
 </servlet-mapping>`

the css and js file link did not call in welcome page, i tried all the method to call the external css file but could not work pleas help me to solve this,I'm newbie help me to solve this .

thank you :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
J John
  • 11
  • Throw away all of this configuration. This makes no sense and makes things worse. I guess you looked at wrong places for the potential answer (this configuration is only recognizable for poorly configured Spring MVC based applications, see also a.o. http://stackoverflow.com/q/870150). The duplicate shows the correct way of referencing CSS/JS (and image) resources in a JSF application. – BalusC Apr 18 '16 at 07:40
  • @Ingrid: OP tagged the question as JSF and PrimeFaces. No sane version of PrimeFaces supports/should be used any other thing than Facelets. Hence the duplicate is in place as is the comment by BalusC – Kukeltje Apr 18 '16 at 08:00

1 Answers1

-1

Servlets are the way to handle dynamic requests. Meaning they should process your request get some data from it and return the result on the basis of that.

In the sample that you posted you're trying to serve static (css, js) content using Servlets, it can be done but then you'll have to create a Servlet class to map with the urls. In that servlet's GET method you'll have to read file from the hard drive and return it as binary stream or text content.

You're missing the <servlet-class> that's why it's not working.

Instead of doing it you can just put all the static content outside WEB-INF directory as below.

app.war/
    /js/app.js
    /css/app.css
    WEB-INF/

Now there no need for a Servlet to serve the CSS and JS files as responsibility of serving the content lies on the servlet container itself like Tomcat.

Link to these files would become as below

http://<host>:<port>/app/js/app.js
http://<host>:<port>/app/css/app.css
11thdimension
  • 10,333
  • 4
  • 33
  • 71