Solved

help me regarding specifying absolute path in Struts view file...

Posted on 2006-07-11
3
265 Views
Last Modified: 2010-04-01
Hi ,
I am using Struts Framework for my web development.

Following is directory structure inside my webroot folder:-
-Econify
     +src
     -webroot
          +JSP
          +images
          +css
          +js
          +META-INF
          +WEB-INF
     
Now In my JSP page when I want to displpay image, I have to use there something like following:-
<img src="<%=request.getContextPath()%>/images/menutopcorn.gif" height="20" width="13">
but, I dont want to use each time <%=request.getContextPath()%> to retieve base path. Also I dont want to use this jsp scriptlet at all in my JSP.
Is there any other solution for above ?
like I should just type just following
<img src="/images/menutopcorn.gif" height="20" width="13">
& I should get the proper output.

How should I do that?

Thanx in advance.
Prash
0
Comment
Question by:Econify
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Meritor
ID: 17080099
assuming your JSP file is loacated in (webroot/jsp) directory and your image file is in (webroot/images) directory

Here is your solution
<img src="../images/menutopcorn.gif" height="20" width="13">

Explanation:

 Your file is in Webroot/JSP now you have to come to one level up for getting access to images directory which is at the same level as JSP direcotry. For this put '../' after that you can access all directories under the webroot directory (images,css,js etc.,)

Regards,
Meritor
0
 

Author Comment

by:Econify
ID: 17080154
hey,
I already know this method in HTML. but I want something that should be unique in all files like something we can do using <html:base /> tag. So that whatever is the location of file, I have to only write path as
<img src="/images/menutopcorn.gif" height="20" width="13">
How this should be done?

thanx.
0
 
LVL 4

Accepted Solution

by:
Meritor earned 500 total points
ID: 17088118
If you dont want to use scriptlet then try to use <bean:write> or <bean:message> tag.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unit test DAO layer 1 139
Spring MVC - sending raw charset to backend 3 223
How to Post an If Statement in JSP 3 60
maven project jars 7 55
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question