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());
%>
------------------------------------