[英]send value from servlet to javascript error (japanese character)
字符串“ああああ”變為“ ????”時出現錯誤 然后將數據從servlet傳遞到javascript。
控制器.java
@RequestMapping(value = "searchbook", method = RequestMethod.POST, produces = "text/plain")
public @ResponseBody String myController(HttpServletRequest request) throws SQLException {
String myItem = request.getParameter("searchid");
PostgrConnect db = new PostgrConnect();
ResultSet rs;
Book book = new Book();
try {
rs = db.getData("select * from mt_book where book_id='" + myItem + "'");
while (rs.next()) {
book.setBook_id(rs.getString("book_id"));
book.setBook_title(rs.getString("book_title"));
book.setAuthor_name(rs.getString("author_name"));
book.setPublisher(rs.getString("publisher"));
book.setPublication_day(rs.getString("publication_day"));
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
return book.getBook_id() + ";" + book.getBook_title() + ";" + book.getAuthor_name() + ";" + book.getPublisher()
+ ";" + book.getPublication_day();
}
javascript
function Search() {
if (checkInputSearch() == "true") {
var date = "";
var searchid = document.getElementById("bookid").value;
$.ajax({
type : "POST",
url : "searchbook",
data : {
searchid : searchid
},
success : function(html) {
var res = html.split(";");
if (res[0] == "null") {
alert(MSG0000 + " " + bookid.value + " " + MSG0004);
Clear();
} else {
alert(MSG0003);
document.getElementById("bookid").value = res[0];
document.getElementById("booktitle").value = res[1];
document.getElementById("authorname").value = res[2];
document.getElementById("publishher").value = res[3];
date = res[4].split("-");
document.getElementById("day").value = date[2];
document.getElementById("month").value = date[1];
document.getElementById("year").value = date[0];
}
},
error : function(e) {
alert(MSG0005);
console.log("Error:" + e);
}
});
}
}
我可以從數據庫中獲取數據:
但是當傳遞給javascript時:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.