Reputation: 7140
I have a button on my .jsp page that I would like to act as a hyperlink, taking users to a particular webpage when clicked. I've got the following code in my .jsp (It's part of a table):
<td><input name="instructionURL" value="<%= StringEscapeUtils.escapeHtml("" + (psi.getInstructionURL()))%>" />
<input type="button" value="Go to link" onclick="location.href='psi.getInstructionURL()'" /></td>
The value of the neighboring table cell correctly displays the variable in question (psi.getInstructionURL()) but a similar call does not work as anticipated for the button's 'onclick' function. Rather, it sends the user from "http://localhost:8080/home/foo" to "http://localhost:8080/home/psi.getInstructionURL()" instead of, as I had hoped, going to the actual webpage (let's say stackoverflow.com). Can I do this with a button, or should I just look into creating a normal link?
If the latter, I'm still looking for a way to ensure that the link goes to the proper, variable, URL rather than the same place irrespective of the current value of psi.getInstructionURL().
Upvotes: 1
Views: 667
Reputation: 35
The code is wrong. This is ok:
<td><input name="instructionURL" value="<%= StringEscapeUtils.escapeHtml("" + (psi.getInstructionURL()))%>" />
<input type="button" value="Go to link" onclick="location.href='<%=psi.getInstructionURL()%>'" /></td>
Upvotes: 1
Reputation: 4092
psi.getInstructionURL() seems to be server side call and therefore you will have to use <% %> to write into onclick handler like,
<input type="button" value="Go to link" onclick="location.href='<%=psi.getInstructionURL()%>'" /></td>
Upvotes: 1