Append strings to our hyperlink in jsp
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>";
You're mixing JSP scriptlets in Java code and the "
after href=
is closing the string too early. This is incorrect. The basic fix would be:
table += "<tr><td><a href=\"person.jsp?id=" + id + "&ssid=" + ssid + "\">Link</a></td></tr>";
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.
You are actually closing the string, by opening a href
attribute, to insert a value. Escape ' " ' characters by using an escape character ' \ '.
table += "<tr><td><a href=\"person.jsp?id=<%=id%>&ssid=<%=ssid%>\">Link</a></td></tr>";
This will work.
精彩评论