Path Trouble

Hi my JSP pages are having trouble accesing external resources such as CSS files, Images, and JavaScript. I am able to forward to the JSP pages fine, but basically nothing else.

I've been printing the path in the JSP with:

<%String getpath=pageContext.getRequest().getRealPath("/");%>

<%=getpath%>

and it prints:

/Users/tbs/Workspace/Office_Space_Mark_2/

that's the correct location under which all of my resources exist and the jsp is running from... If i manually type in the address of something i want ie:

http://localhost:8080/Office_Space_Mark_2/view_style.css it doesn't come up... eventhough it's directly under that directory.

any suggestions?

[724 byte] By [tomisinaa] at [2007-11-27 5:55:39]
# 1

The getRealPath is not intended for generating URLs, but rather for accessing files on the servers disk.

Absolute references don't work so well in web applications because your web application root is normally not the same as the web server root.

The best solution I know of to this problem is to use a base tag. That is an HTML tag which tells the page where to resolve all relative references from.

Struts has a custom tag <html:base> which generates it automatically.

evnafetsa at 2007-7-12 16:24:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...