Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3394
  • Last Modified:

JSP to reference anchor tag

Hello,
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?

Thanks!

John
0
jlm151
Asked:
jlm151
1 Solution
 
gagaliyaCommented:
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:

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

<script type="text/javascript">
document.testform.action="jsptwo.jsp?variabletopass=<%=your_variable%>";
document.testform.submit();
</script>
<form method="get" id="testform">  
........
</form>
</body></html>

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.

gaga
0
 
jlm151Author Commented:
That worked!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now