0

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>";
eddie skywalker
  • 189
  • 1
  • 5
  • 16

2 Answers2

1

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.

d1e
  • 6,372
  • 2
  • 28
  • 41
1

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555