-1

in my web project the content - jsp, js, images and css files are kept in seperate folders, in order to specify a css in any jsp i write code as ../../css/xyz.css and this works fine in every case except when i return from a servlet call.

i am unable to identify the problem. kindly help. when i check the context path and the URLs formed they are fine line - localhost:8080\TestProject\jsp\menu\createmenu.jsp however the .css is being looked at the path localhost:8080\css\menu\menu.css

  • possible duplicate of [Browser can't access CSS and images when calling a Servlet which forwards to a JSP](http://stackoverflow.com/questions/3655316/browser-cant-access-css-and-images-when-calling-a-servlet-which-forwards-to-a-j/3658735#3658735) – BalusC Nov 21 '11 at 12:13

2 Answers2

0

../ Means the parent folder (The folder before current one).

So ../../css/xyz.css means two folders before your url

so localhost:8080\TestProject\jsp\menu\createmenu.jsp => ../../ will point to localhost:8080\TestProject\ where your css remains.

In case of "return from a servlet call" the folder structure may not be same.

So the best case is use a jsp template to include css in views

nidhin
  • 6,661
  • 6
  • 32
  • 50
  • Can u tell me how do i set the folder structure in case of return from servlet? bcoz the .jsp content is displayed fine, even the other jsps imported into it is getting displayed only the .css is not being picked – simran sodhi Nov 21 '11 at 09:55
  • hi i added few .if you ask me more , i will tell you more ..i want to know what you have ? then what you need ?Are you using the web server ? or application server ? – Adalarasan Sachithanantham Nov 21 '11 at 12:16
0

If you running the Web application using the Tomcat (Web-Server)

Follow:

1.try to search "Apache Software Foundation"  then "Tomcat"
2.Create you Project folder inside of "Tomcat" (Ex:c:\..\Apache Software Foundation\Tomcat\webappps\Root\MyProject)
3.Inside of MyProject creating one folders .Don't Change the folder name it's case sensitive too.The folder name is WEB-INF
4.Then after creating two folders are classes and lib .
5. c:\..\Apache Software Foundation\Tomcat\webappps\Root\MyProject\WEB-INF\classes and c:\..\Apache Software Foundation\Tomcat\webappps\Root\MyProject\WEB-INF\lib
  (Don't change the folder name WEB-INF it should be case-sensitive too.)
6.Creating the xml file the file name as web.xml
7.web.xml is the file it's described your deployment descriptor which are the preferences to the set in your web project.
8.For example, the session timeout,index page,database username ,database passwords,servlet etc.
9.Then creating the jsp file using the separate folder that folder is named for as your own wish.
10.But that is user understandable. (Ex.Jsp-folder name)
11.The style sheet (.css) and images (.img..jpeg,.gif) are maintained in the separate folder.
12.For example,css,images
13.All the css files are stored inside of the css folder and all the images are stored in the images folder.
14.Strucute are c:\..\Apache Software Foundation\Tomcat\MyProject\css and c:\..\Apache Software Foundation\Tomcat\MyProject\images
15.lib folder contains the supporting libraries and should be placed in the lib folder.
16.css can be using in the jsp files example (<link HREF="../theme/screens.css" REL="stylesheet" TYPE="text/css" >)