?
Solved

JSP Breadcrumbs

Posted on 2005-04-19
5
Medium Priority
?
3,464 Views
Last Modified: 2012-06-27
I am just learning JSP, this should be a pretty easy question but I cannot figure it out. I have a menu at the top of my site that is an include file, menu.jsp. It has links to the rest of the site like this:

              <ul id="secondary">
                        <li><a href="significance.jsp">Significance</a></li>
                        <li><a href="hottopics.jsp">Hot Topics</a></li>
                        <li><a href="diseaseindex.jsp">Disease Index</a></li>
                        <li><a href="diseasetype.jsp">Disease by Type</a></li>
                        <li><a href="diseasespecies.jsp">Disease by Affected Species</a></li>
                        <li><a href="humanhealth.jsp">Human Health Connections</a></li>
                        <li><a href="animalhealth.jsp">Domestic Animal Health</a></li>
              </ul>

What I want to happen is that when you are actually at one of those pages the <a> tags get turned into a <span>. i.e., if you were at "hottopics.jsp" the html would look like this:

              <ul id="secondary">
                        <li><a href="significance.jsp">Significance</a></li>
                        <li><span>Hot Topics</span></li>
                        <li><a href="diseaseindex.jsp">Disease Index</a></li>
                        <li><a href="diseasetype.jsp">Disease by Type</a></li>
                        <li><a href="diseasespecies.jsp">Disease by Affected Species</a></li>
                        <li><a href="humanhealth.jsp">Human Health Connections</a></li>
                        <li><a href="animalhealth.jsp">Domestic Animal Health</a></li>
              </ul>

I want this to happen dynamically so I can maintain the links in the menu through one file. I was trying to get this to work by using window.location.href and some if-then statements to insert the right html but I couldn't even get window.location.href to work. Is window.location.href Javascript only? I am still confused by the diffferences between the languages.

Thanks
0
Comment
Question by:tommyboy22481
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13817419
>>Is window.location.href Javascript only?
Yes

You need to check for request.getServletPath() to get the name of the JSP or servlet and then do an if statement to change the html from <a> to <span>

>>I am still confused by the diffferences between the languages.
Yes, it can be a pain at first but the only way you will learn is by doing what you are doing by coding.
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 500 total points
ID: 13817474
Here's a basic and somwaht long winded version of how you do it. Also notice the use of String.equals(String) not == as in java they have a different meaning.

<%
if ( "/index.jsp".equals(request.getServletPath() ) ){
      out.println("<span>here</span>");
}else{
    out.println("<a href=\"#\">there</a>");
}
%>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13817563
just a little addition to what bloodred is saying..
I normally use .contains i.e.
if ((request.getServletPath()).contains("/index.jsp" ))
{
  out.println("<span>here</span>");
}else{
    out.println("<a href=\"#\">there</a>");
}
%>

( feels more secure with it... if I remember correctly servlet 2.2 used to return it with / and 2.3 returns it without "/" or vice versa
0
 

Author Comment

by:tommyboy22481
ID: 13817603
Thank you, I knew it wasn't very hard.

Where would I look up functions like getServletPath? My main problem I think is I dont have a good language reference. I use www.devguru.com for CSS and HTML reference but I havn't been able to find something like that for JSP.

(I bumped the points a bit for the second quesiton)
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 100 total points
ID: 13817629
Well there are a lot of site for them but I always prefer java.sun.com... ( after all they wrote it!!)..

www.jguru.com is also are very good reference...

and o'reilly's servlet reference guide is the best...
http://www.onjava.com/topics/java/JSP_Servlets

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

850 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