• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ajax-jsp special characters like %,&

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a form on one jsp, with a text box. The user inputs the value like "50%", after clicking a button i send this textbox value to the new jsp using AJAX.


In the second file, the request.getparameter("name") is getting failed for the "50%" or any string which includes "%".

Please tell me how to send these special characters from form controls to the backend DB through servlet or jsp.



file1: form

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

<%

request.setCharacterEncoding("UTF-8");
%>
<META http-equiv="Content-Type" content="application/x-www-form-urlencoded; charset=UTF-8">

<script language="javascript" charset="utf-8">
function ganeshme()
{
//alert(document.ganesh.meranam.value);
ajaxFunction(document.ganesh.meranam.value);
}

function ajaxFunction(f)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
alert('return:'+xmlhttp.responseText);
}
}
var url="time.jsp";
var mera="&mera="+f;
url=url;

xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type","text/html;UTF-8");
xmlhttp.setRequestHeader("Accept","%");
xmlhttp.send(mera);
}

</script>
<form name="ganesh" >
<input type="text" name="meranam" />
<input type="button" value ="hit it" onclick="ganeshme()"/>
</form>

----------------------------------------


file2 form processing

--------------------------

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

<%

String namee=request.getParameter("mera");
System.out.println("charater" +request.getCharacterEncoding());
System.out.println("charater content type: "+request.getContentType());
System.out.println("namee" +namee);
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(namee+new java.util.Date());
%>


------------------------------------



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

The percent sign has special meaning; it's used to escape GET parameters. Requests containing special characters should be URL-encoded.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you click follow link to study and solve the problem of yours,it may be helpful
http://servlets-jsp.blogspot.com/2010/02/ajax-autocomplete-issues-with-xml.html
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavan Kumar Reddy wrote:you click follow link to study and solve the problem of yours,it may be helpful
http://servlets-jsp.blogspot.com/2010/02/ajax-autocomplete-issues-with-xml.html


No, that is not the correct way to deal with the problem. The strings to be sent to the server must be URL-encoded, and not HTML-encoded.

The function encodeURIComponent() should be used.

A form submission normally handles this on your behalf, but when using raw Ajax, you must do it yourself.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic