将变量转换为超链接
我的 .jsp 页面上有一个按钮,我想将其用作超链接,在单击时将用户带到特定的网页。我的 .jsp 中有以下代码(它是表格的一部分):
<td><input name="instructionURL" value="<%= StringEscapeUtils.escapeHtml("" + (psi.getInstructionURL()))%>" />
<input type="button" value="Go to link" onclick="location.href='psi.getInstructionURL()'" /></td>
相邻表格单元格的值正确显示有问题的变量 (psi.getInstructionURL()),但类似的调用无法按预期工作按钮的“onclick”功能。相反,它将用户从“http://localhost:8080/home/foo”发送到“http://localhost:8080/home/psi.getInstructionURL()”,而不是像我希望的那样,转到实际的网页(比如说 stackoverflow.com)。我可以使用按钮来完成此操作,还是应该考虑创建一个普通链接?
如果是后者,我仍在寻找一种方法来确保链接转到正确的变量 URL,而不是相同的位置,无论 psi.getInstructionURL() 的当前值如何。
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().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
psi.getInstructionURL() 似乎是服务器端调用,因此您必须使用 <% %>;写入 onclick 处理程序,例如
psi.getInstructionURL() seems to be server side call and therefore you will have to use <% %> to write into onclick handler like,
代码错误。这没问题:
The code is wrong. This is ok: