user2372154
user2372154

Reputation: 27

how to remove %20 from query string URL in JSP

     <a href=" 
    javascript:openWin
                            ('printlist.jsp?CTextSearch=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtSearch"),"UTF-8")%> & CTextNumbr=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtNum"),"UTF-8") %> & CYear=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbYear"),"UTF-8") %> & CSectionNo=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbSection"),"UTF-8") %>&CDatefrom=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateFrom"),"UTF-8") %>&CDateto=<%=  URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateTo"),"UTF-8")  %>'


                            )" id="ctl00_PagingHolder_btnPrint" class="gena" onclick="">




                            Print List</a>

This is my query string am sending the value to print list.jsp But in Each value am Getting

localhost:8080/Cbdt-cir-not/printlist.jsp?CTextSearch=%20&%20CTextNumbr=14%20&%20CYear=%20&%20CSectionNo=&CDatefrom=&CDateto=    %20

so am not getting the value of from request.get parmeter please tell me where am doing wrong i have Tried much But unable to Do.

Upvotes: 1

Views: 2412

Answers (4)

No Idea For Name
No Idea For Name

Reputation: 11577

i just want to add to @Peter Rader answer that the reason you have all those %20 is because The specification for URLs (RFC 1738, Dec. '94) poses a problem, in that it limits the use of allowed characters in URLs to only a limited subset of the US-ASCII character set:

"...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'(),"

[not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."

HTML, on the other hand, allows the entire range of the ISO-8859-1 (ISO-Latin) character set to be used in documents - and HTML4 expands the allowable range to include all of the Unicode character set as well. In the case of non-ISO-8859-1 characters (characters above FF hex/255 decimal in the Unicode set), they just can not be used in URLs, because there is no safe way to specify character set information in the URL content yet [RFC2396.]

that's why when you try to put empty spaces it translate it to "%20", it's just a representation of charecters

Upvotes: 1

Waqas Memon
Waqas Memon

Reputation: 1249

Use URLEncoder with UTF-8 character-set for encoding and decoding URLs, Use encodeURI and decodeURI in JavaScript when you construct URLs in Java Script.

Upvotes: 1

Grim
Grim

Reputation: 1986

Use this:

('printlist.jsp?CTextSearch=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtSearch"),"UTF-8")%>&CTextNumbr=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtNum"),"UTF-8") %>&CYear=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbYear"),"UTF-8") %>&CSectionNo=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbSection"),"UTF-8") %>&CDatefrom=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateFrom"),"UTF-8") %>&CDateto=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateTo"),"UTF-8")  %>'

instead of

('printlist.jsp?CTextSearch=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtSearch"),"UTF-8")%> & CTextNumbr=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtNum"),"UTF-8") %> & CYear=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbYear"),"UTF-8") %> & CSectionNo=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$cmbSection"),"UTF-8") %>&CDatefrom=<%=URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateFrom"),"UTF-8") %>&CDateto=<%=  URLEncoder.encode(request.getParameter("ctl00$SearchCriteriaHolder$txtDateTo"),"UTF-8")  %>'

There are a cuple of whitespaces between the key-value-pairs that are interpreted as a part of the congrete key/value. So your key is not "CYear", your key is " CYear", fix the problem by removing those whitespaces that are part of the key or value.

Upvotes: 2

Makky
Makky

Reputation: 17461

You can try URLDecoder

    String test = "ocalhost:8080/Cbdt-cir-not/printlist.jsp?
                   CTextSearch=%20&%20CTextNumbr=
                   14%20&%20CYear=%20&%20CSectionNo=&
                   CDatefrom=&CDateto= %20";


System.out.println(URLDecoder.decode(test, "utf-8"));

Upvotes: 1

Related Questions