JSP to reference anchor tag

Posted on 2004-11-19
Last Modified: 2008-01-09
This is a pretty easy question for anyone who knows the answer.  Basically, I'm building an web page using JSP.  An anchor is set at the top of the page and I need to change what that is pointing to (href) based on a variable at the bottom of the program.  How do I use jsp to reference an anchor tag that's located elsewhere in the program?


Question by:jlm151
    LVL 1

    Accepted Solution

    not clear what you mean exactly. but you cannot directly do it in 1 jsp using java as html are generated sequentially on serverside and once generated cannot be changed by serverside jsp. Two options

    option 1) have two jsp, passing the variable from one to another using form.  something like:

    <html><head></head><body>Loading please wait....
    <%String your_variable="somevalue";%>

    <script type="text/javascript">
    <form method="get" id="testform">  

    jsptwo: this is your real jsp that is shown to the user
    <a href="<%=request.getParameter("variabletopass")%>">anchor or whatever </a>

    option2) use javascript, set one of the javascript variable to a jsp/java variable at the bottom of your jsp. then you can use javascript to manipulate what the html is pointing to on the client side.


    Author Comment

    That worked!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Synchronize a new Active Directory domain with an existing Office 365 tenant
    Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now