将字符串附加到 jsp 中的超链接
你能给我任何简单的例子吗?
例如,当我尝试添加字符串时出现错误:
String id = line.split(" / ")[0];
String ssid = line.split(" / ")[1];
table += "<tr><td><a href="person.jsp?id=<%=id%>&ssid=<%=ssid%>">Link</a></td></tr>";
Can you give me any simple example?
For example I took an error when I try to add my strings:
String id = line.split(" / ")[0];
String ssid = line.split(" / ")[1];
table += "<tr><td><a href="person.jsp?id=<%=id%>&ssid=<%=ssid%>">Link</a></td></tr>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在 Java 代码中混合 JSP scriptlet,并且
href=
之后的"
过早地关闭了字符串。这是不正确的。基本修复将是:请注意,您还希望
rel="nofollow noreferrer">
URLEncode
这些参数可以防止 /3177733/how-to-avoid-java-code-in-jsp-files">停止使用 Java 代码和 JSP scriptlet 进行演示。您可以使用 JSTL
和
创建带有 URL 编码参数的链接。You're mixing JSP scriptlets in Java code and the
"
afterhref=
is closing the string too early. This is incorrect. The basic fix would be:Note that you would also like to
URLEncode
those parameters to prevent that you end up with a malformed URL.Better would be to stop using Java code and JSP scriptlets for presentation. You could use JSTL
<c:url>
and<c:param>
to create links with URL-encoded parameters.您实际上是通过打开
href
属性来关闭字符串以插入值。使用转义字符 ' \ ' 转义 ' " ' 字符。这会起作用。
You are actually closing the string, by opening a
href
attribute, to insert a value. Escape ' " ' characters by using an escape character ' \ '.This will work.