File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes linking css and javascript  with JSP pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "linking css and javascript  with JSP pages" Watch "linking css and javascript  with JSP pages" New topic
Author

linking css and javascript with JSP pages

srinivasan ramarao
Greenhorn

Joined: Oct 02, 2006
Posts: 5
hi,

i am new to this comunity and currently i am doing a project based on MVC architechture. since i am new to JSP,i need help on connecting my external style sheet with my JSP pages..actually i converted a html page into JSP page. it is working quite well in my TOMCAT server AND MYSql back end..But the problem is, it is not showing any pictures and css effects and also i created a roll over effect using javascript..but after i converted these into JSP pages, all my design effects are lost and only text contents are displayed..should i use any concept related to taglibs and cant i use same old css and java script in my JSP pages..Please Give suggestions..THANK U IN ADVANCE..

[ January 29, 2007: Message edited by: srinivasan ramarao ]
[ January 29, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

I'd bet my left ear that you are using page-relative addressing for your CSS and image files. Bad idea.

Search this forum for previous discussions of using server-relative URLs for external resources.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
srinivasan ramarao
Greenhorn

Joined: Oct 02, 2006
Posts: 5
Originally posted by Bear Bibeault:
I'd bet my left ear that you are using page-relative addressing for your CSS and image files. Bad idea.

Search this forum for previous discussions of using server-relative URLs for external resources.


so..cant i use my old way of adding css files into a web page..i mean as i used to do in html pages..i have stored all the required css,pictures and javascripts in the same folder..so which statement or tag should i use in jsp to make it possible or in what way of approach can i do it.u mentioned about server related url.. i cant get you..??
Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
hey wether you make a html page or jsp page that wont affect your css or javascript just import/link these files in your pages or declare the scripts and styles within the page.

I mean you can either associate a page to a js file or declare your javascripts within the page.

look below -
this how you get your css file to your page
<link href="path/xyz.css" rel="stylesheet" type="text/css">
this how you get your js files that you have made on your page
<script language="javascript" src="<%=JsFilePath%>/cr/ManageHCP.js"></script>
srinivasan ramarao
Greenhorn

Joined: Oct 02, 2006
Posts: 5
Originally posted by Avneet Singh:
hey wether you make a html page or jsp page that wont affect your css or javascript just import/link these files in your pages or declare the scripts and styles within the page.

I mean you can either associate a page to a js file or declare your javascripts within the page.

look below -
this how you get your css file to your page
<link href="path/xyz.css" rel="stylesheet" type="text/css">
this how you get your js files that you have made on your page
<script language="javascript" src="<%=JsFilePath%>/cr/ManageHCP.js"></script>


thank you for your suggestion. it helped me. i got it right..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Bear's point, and it's an important one, is that your pages will be more robust, if you make your links relative to the root of the webapp instead of being relative to the page location. This is especially important if you start using an MVC architecture or if you use response.forward to forward to a page in another directory.

The following example creates a link to a image that is relative to the root of the application.


Or, for pre JSP 2.0 containers:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
srinivasan ramarao
Greenhorn

Joined: Oct 02, 2006
Posts: 5
Originally posted by Ben Souther:
Bear's point, and it's an important one, is that your pages will be more robust, if you make your links relative to the root of the webapp instead of being relative to the page location. This is especially important if you start using an MVC architecture or if you use response.forward to forward to a page in another directory.

The following example creates a link to a image that is relative to the root of the application.




Or, for pre JSP 2.0 containers:



thank you Ben Souther for making me to clear my doubt...i will try the same..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: linking css and javascript with JSP pages
 
Similar Threads
CSS displayed, CSS not displayed
package doesn't exist exception
good editor
Returning JavaScript via Ajax
finding the jsp