Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  51] [ 4]  / answers: 1 / hits: 16426  / 15 Years ago, wed, december 30, 2009, 12:00:00

I am having a JSP file with the below codes



 <HTML>
<head>
<link rel=stylesheet type=text/css href=../CSS/home.css />
<link rel=stylesheet type=text/css href=../CSS/left.css />
<script type=text/javascript src=../js/friend_request.js></script>

</head>
<body>
<div class=menu>
<form name=search_form method=post>
<table id=menutabel class=color>
<tr>
<td class=alt><A class=oneHREF=home.jsp>Home</A></td>
<td class=alt ><A class=oneHREF=../HTML/falbum.html>My Album</A></td>
<td class=alt ><A class=oneHREF=../HTML/MyDiary.html>My Diary</A></td>
<td class=alt ><A class=oneHREF=../HTML/MyFriends.html>Myfriends</A></td>
</tr>
</table>
</form>
</body>
</html>


When i run this JSP file individually on the server both the CSS file and the Java script file are loading correctly ,but the problem is when i forward the request from a servlelt both the CSS and the Java Script file is not loading. Can anyone help me out with this problem?



I am having all the html, jsp, CSS, java script into separate folders.



Like



Web-content

|



|-- HTML (This folder will have all the HTML files)



|--- CSS (This folder will have CSS files)

|--- js

|--- JSP


More From » java

 Answers
93

Make use of the HTML <base> tag. It denotes the base URL of all relative URL's used in the final HTML output. If you set it with HttpServletRequest#getContextPath(), then ALL links in your page will be relative to the http://example.com/contextname URL, which is http://localhost:8080/Projectname in your case.



<!doctype html>
<html lang=en>
<head>
<base href=${pageContext.request.contextPath}>
<link rel=stylesheet type=text/css href=css/style.css>
<script type=text/javascript src=js/script.js></script>
</head>
<body>
<ul>
<li><a href=html/page.html>HTML page</a></li>
<li><a href=jsp/page.jsp>JSP page</a></li>
</ul>
</body>
</html>


Note that you should not start the relative URL's with /, otherwise they will lead to the domain root, e.g. http://example.com/yourlink.



By the way, links doesn't need to be placed inside a form. Also HTML tables ought to be used for tabular data only, not for other content. Learn semantic HTML as well.


[#97960] Friday, December 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeniferjaliyahf

Total Points: 650
Total Questions: 104
Total Answers: 86

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
jeniferjaliyahf questions
Fri, Feb 11, 22, 00:00, 2 Years ago
Thu, Feb 10, 22, 00:00, 2 Years ago
Thu, Jun 17, 21, 00:00, 3 Years ago
Thu, Mar 25, 21, 00:00, 3 Years ago
Wed, Feb 17, 21, 00:00, 3 Years ago
;