Apologies for any language barriers as English is not my first language.
I am currently developing an application in JSP and encountering an issue with a field labeled "comments" in one of my forms. Upon form submission, the value of this field is sent to my servlet via an ajax request.
var request = 'mainServlet?command=SendRequest';
request += ('&comments=' + $('#comments').val());
The problem arises when the field contains characters like "<" or ">". $('#comments').val() converts them to "<" or "&gl", for example: becomes < ;test&gl ;
When trying to retrieve the value in my servlet using:
String comments = request.getParameter("comments");
The URL appears as follows:
mainServlet?command=SendRequest&comments=< ;test&gl ;
This results in request.getParameter("comments"); returning an empty string.
I considered manually replacing the string like < before passing it to the servlet, but I am wondering if there is an easier solution to this issue?
Thank you.
Edit: Additionally, the comments variable will be reused in another JSP.