0
votes

I have 2 jsp pages where value entered in a textbox in share.jsp is encoded,decoding is done in forwarded.jsp page. if the text entered in the txt box is "xyz +" then decoding is incorrect decoding result is only "xyz" i.e "+" does not get deocded.

Page encoding in both the pages is same:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

snippet:-

share.jsp

document.getElementById('hiddenFolderList').value = (encodeURI(document.getElementById('folderId').value,"UTF-8"));

forwarded.jsp

String folders=java.net.URLDecoder.decode(request.getParameter("hiddenFolderList"),"UTF-8");

I also checked in URL Encode and Decode Tool there also "+" does not get decoded how to escape/prevent this?

1

1 Answers

0
votes

The encodeURI javascript function "encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters)"

The example page you provided seems to be working ok... a space is encoded to a +, so a + will be decoded as a space. if you encode a + it will turn into a %2B.