I want to send a Unicode to JSP page using javascript. I went throug the internet but still could not find an answer. It always shows me something like '???? ????'. Can anybody tell me the answer please.
Here is my method in controller
@RequestMapping(value = "/conv", method = RequestMethod.POST)
public @ResponseBody
String add(@RequestParam(value = "input", required = true) String input) throws UnsupportedEncodingException {
String result = Run.getTranslation(input);
log.info(result);
byte[] bytesInUTF8 = result.getBytes("UTF-8");
String stringUsingUTF8 = new String(bytesInUTF8, "UTF-8");
return stringUsingUTF8;
}
Here is my JavaScript code (test.js)
$(document).ready(function(){
$("#submit").click(function(){
var input = $("#in").val();
$.ajax({
type : "POST",
url : "conv",
data : "input=" +input,
//contentType: 'text/plain; charset=utf-8',
success : function(response) {
$("#out").val(response)
},
error : function(e) {
alert('Error msg: ' + e);
}
});
});
$("#clear").click(function(){
$("#out").val("");
$("#in").val("");
});
});
This is my JSP page
<Doctype html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="<c:url value="/resources/js/jquery.min.js"/>"></script>
<script src="<c:url value="/resources/js/test.js"/>"></script>
<!-- You can add resources to page like above, .css and .js should be in resources folder -->
</head>
<body>
<h1>Translator</h1>
<h4>Input</h4>
<textarea id="in" rows="5" cols="100"></textarea>
<br>
<h4>Output</h4>
<textarea id="out" rows="5" cols="100"></textarea>
<br><br>
<button id="clear"> Clear</button> <button id="submit"> Convert</button>
</body>
</html>