Dear sir
In my project i have to pass variables when a user click on the link i.e there is full address
of a client which is getting from a table,when user click on this link all information is displayed,but the problem is if there is a space in the address as(united state) variables,only null value is displayed.
Please help

Dani AI

Generated

— building on what and suggested, here are practical, maintainable fixes that avoid the common pitfalls in your out.println approach.

Prefer passing a stable key (ID) and rendering the friendly address only for display. Move DB access into a servlet/DAO, put the row object into the request, and let the JSP use JSTL to build the link (JSTL will encode parameters for you):

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<td align="center">
  <c:url var="reportUrl" value="/report.jsp">
    <c:param name="id" value="${row.id}" />
  </c:url>
  <a href="${reportUrl}">${row.address}</a>
</td>

If you must send the full address string (not recommended), use the same c:url/c:param pattern or encode it server-side before inserting into the href:

String href = "report.jsp?address=" + URLEncoder.encode(address, "UTF-8");

Troubleshooting notes:

  • Always put quotes around href values in generated HTML — missing quotes can break links when values contain spaces or punctuation.
  • Escape any displayed user data to avoid XSS (JSTL/EL or fn:escapeXml).
  • Use UTF-8 consistently (request/response encoding) so non-ASCII characters round-trip correctly.
  • Prefer GET with an ID for lookup; use POST only if the data is long or sensitive.

References: JSTL core tags (c:url/c:param) and Java URL encoding are helpful starting points — see the JSTL docs and the URLEncoder javadoc for details.

Recommended Answers

All 3 Replies

Spaces are not acceptible Url characters. Use the Url equivalent, %20, whenever you need a space in the information transferred to get the best results. Or better yet, use a built-in Url Encoding method, like URLEncoder.encode(), to encode the entire Url before it is processed and take care of all non-Url-acceptible characters.

~ mellamokb

Thanks for the reply,but my problem is i m getting value from table as given in the code below
out.println(" <TD style=\"font-family:Verdana; font-size:11px; font-style:normal; font-weight:normal; vertical-align:middle; color:#3366FF;\"align=\"center\"><a href=report.jsp?address="+rs.getString("address")+">"+rs.getString("address") +"</a></td>");
In the address client has to submit his address,but if there space in the address value as (united state) then mycode is not working
Please Help

You have been given your answer.

A URI can't contain any spaces and some other special characters, and if they do, they need to be encoded. With the way you are currently doing things, when the country name with spaces is encountered, the URI becomes report.jsp?address=some address when it should have been report.jsp?address=some%20address .

Using scriptlets in your JSP file is a bad practice not to mention that accessing a database from the JSP file is disastrous.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.