2

I have created Struts2 application using Maven. In this application I have created two namespaces, first is tc and the second one is cmpui. From the JSP page, I am trying to access .css files, but it is giving me 404 error.

Location of JSP page is :

webapp\tc\layout\stylesheets.jsp

Location of CSS file is :

WEB-INF\css\default.css

Code on JSP page is

<link rel="stylesheet" type="text/css" href="../WEB-INF/css/default.css">

Any suggestion please.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Rahul
  • 35
  • 2
  • 11
  • What is the full path of stylesheets.jsp and default.css? I think your href is wrong. – Juru Oct 20 '14 at 10:14
  • 2
    You can not access resource directly which are in WEB-INF but you could using context object, This link might help ful http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder – Naveen Ramawat Oct 20 '14 at 10:23
  • Thanks for the reply guys. I have made some changes in jsp page but still it is giving me same error. Currently in browser, path for css is showing as http://servername:port/contextpath/css/default.css – Rahul Oct 20 '14 at 10:27
  • Please Find the folder Structure for the reference. [1]: http://i.stack.imgur.com/vx3Mf.png – Rahul Oct 20 '14 at 10:33
  • Put css outside of web-inf directory. And use `` tag to reference them. – Aleksandr M Oct 20 '14 at 12:06
  • @AleksandrM : If I put css folder outside WEB-INF Folder, it will be consider as another namespace, right? Correct me if I am wrong. And also I want to create folder for js files. Do I need to create outside WEB-INF folder? – Rahul Oct 20 '14 at 12:11
  • What do you mean by another namespace? IMO you can ignore namespaces right now and solve your current problem. Yes, outside of web-inf for js files also. – Aleksandr M Oct 20 '14 at 12:21
  • 1
    Thanks for reply Aleksandr M. Css files are accessible if I put css folder outside WEB-INF folder. – Rahul Oct 20 '14 at 12:48

1 Answers1

3

You can not access a resources that are under WEB-INF folder. Move your static resources to another place accessible by Struts2 (for example, web root). And use s:url tag to build the URL.

<link rel="stylesheet" type="text/css" href="<s:url value='/css/default.css'/>">
Roman C
  • 49,761
  • 33
  • 66
  • 176