0

I am trying to pass a string parameter that has html content in it.

<%
String myparam = "<td>some text</td>";
%>
<td>
<a href="page.jsp?myparam=<%=myparam%>">Visit W3Schools</a>
</td

It fails to send and recognizes my string as html code.

4
  • use ajax call for complete this task Commented Nov 9, 2017 at 13:34
  • So its not possible to do it using jsp Commented Nov 9, 2017 at 13:36
  • try like this <a href=<%= "page.jsp?myparam="<%=myparam%>"" %> >Visit</a> Commented Nov 9, 2017 at 13:46
  • was a mistake. Still does not work with equal sign Commented Nov 9, 2017 at 13:48

2 Answers 2

1

To turn a text into URL passable parameters, and to have no HTML <, > inside of the HTML attribute, do:

String myparam = URLEncoder.encode("<td>some text</td>", "UTF-8");

At the top of the JSP you maybe have to import java.net.URLEncoder.

<%@ page import="java.net.URLEncoder" %>
Sign up to request clarification or add additional context in comments.

Comments

1

This should be indeed possible. To insert the value of a variable, use

<%= %>

like this:

<a href="page.jsp?myparam=<%=myparam%>">Visit W3Schools</a>

But sending html inside a url is not a good idea. It´s easy to manipulate and you will get security issues due to code injection.

And if you really really need to send html in the url, you need to escape the html specific characters.

1 Comment

I had placed the equal sign just left it out by mistake. Still does not work with edit. If its not possible then i will look for another way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.