This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes fail to include file from upper directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "fail to include file from upper directory" Watch "fail to include file from upper directory" New topic
Author

fail to include file from upper directory

H Austy
Greenhorn

Joined: Dec 15, 2008
Posts: 3
I just moved server and found this problem below.

Directory structure:
/home/mydomain/public_html/ - index.jsp
- include
- validate.jsp
- member
- login.jsp


Basically I am trying to include validate.jsp from login.jsp

So in login.jsp I wrote:
<%@ include file="/include/validate.jsp"%> // THIS ONE GIVES ERROR
<%@ include file="../include/validate.jsp"%> // ALSO GIVES ERROR
<%@ include file="/../include/validate.jsp"%> // ALSO ERROR

Then I try to do some debugging. I put these line of codes in the login.jsp

application.getRealPath("/")
//Returns: /home/mydomain/public_html/member/


application.getRealPath("../include/validate.jsp")
//Returns: /home/mydomain/public_html/member/../include/validate.jsp

Can anyone tell me how to make this work?

I was even thinking of putting the validate.jsp in all subfolders temporarily. But this one is a rather desperate move. I have many config files in the /home/mydomain/public_html/include/.

Thanks all in advance for the help and time on my request.. Cheers..


Regards,<br />Austy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Originally posted by Bear Bibeault:
Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.


Honestly, that's horrible when used for images, CSS and JS.

If really needed, I would just set it at one place using <base> tag in the HTML head.
[ December 16, 2008: Message edited by: Bauke Scholtz ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bauke Scholtz:


Honestly, that's horrible when used for images, CSS and JS.

If really needed, I would just set it at one place using <base> tag in the HTML head.

[ December 16, 2008: Message edited by: Bauke Scholtz ]


And if the context path changes, how do you update all of the base tags?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use it in base path?

There's no need to pollute all img/css/js links for that.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

So, if your application's context path was "abc" and you were accessing it at the domain "xyz.com" with:
http://www.xyz.com/abc

How would you build links to your css sheets and JS pages?


Then, what if you needed a test copy with a context path of "abctest"?
How would you update the links?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Not needed. Set it in base path.

http://www.w3.org/TR/html401/struct/links.html#h-12.4
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What's not needed and (in the case above) what would you set the base path to?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

I avoid the base tag for reasons I will not go into here because this topic is about the include mechanism, not client-requested resources. The base tag is useless for this topic.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Fine. It was just an opinion.
H Austy
Greenhorn

Joined: Dec 15, 2008
Posts: 3
Originally posted by Bear Bibeault:
Never use page-relative addressing in a web app.

See the JSP FAQ article on resource URLs for information on how to properly form URLs in a Java web app.



I have tried to use "server-relative" path as suggested by putting "/xyz" at the beginning of my links as my application is mapped to "/xyz" as the context path. HOWEVER , still to no avail.

<Host name="xyz.org.cn" appBase="/home/xyz/public_html">
<Alias>www.xyz.org.cn</Alias>
<Context path="/xyz" reloadable="true" docBase="/home/xyz/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

Is the rest of the URL ok? What happens when you use the same URL in the address bar of the browser?
H Austy
Greenhorn

Joined: Dec 15, 2008
Posts: 3
The rest of the page also not ok.

Any idea on which other configuration file that I need to change other than server.xml to pake context path works? thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fail to include file from upper directory
 
Similar Threads
Problem in using ejbjar task of Ant
include doesn't recognize relative path from sub folder
Problem in running jsp page in javawebserver
How to use Actions inside Javascript menus???
Getting userDir to work in apache