我的网络应用程序有一些问题,如下所示:
1)我通过 Jquery ajax 调用控制器并以 JSON 格式获取响应数据。
2) 该控制器点击数据库并从数据库中检索数据,检索到的数据为阿拉伯文格式。
3) 然后我在 jsp 页面中构造的 Jquery 对话框中填充该数据,但该数据格式不正确
======================ajax调用======================
$.ajax({
url: "Login/getUserData.html",
type: "GET",
cache: false,
async: false,
dataType:"json",
contentType: "application/json; charset=utf-8",
success : function(data) {
jQuery.parseJSON(data);
if(data!=null)
{
//*****************Start***************
$("#post").dialog({
height : 500,
width : 550,
resizable: false,
modal : true,
open: function(){
$('#cName').val(data.fname+" "+data.lname); $('#cEmail').val(data.email);
$('#cNo').val(data.contact);
$('#dateL').val(data.currentDate);
}
});
//*****************End***************
}
else
{
$("#notLoggedInMessageDialog").dialog('open');
}
},
error:function(){
alert("Error occured");
}});
=====================LoginController.java =================
@Controller
@RequestMapping("/Login/")
@Scope("request")
public class LoginController {
/*
* method to get log-id user's data
*/
@RequestMapping(value = "/getUserData", method = RequestMethod.GET, produces = {"application/json; charset=UTF-8"})
@ResponseBody
public String getUserData(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
System.out.println("================inside LoginController.getUserData()=============");
UserModel uModel = (UserModel) request.getSession().getAttribute("user");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charaset=UTF-8");
String user = null;
if (uModel != null) {
UserModel newUserModel = new UserModel();
newUserModel.setuId(uModel.getuId());
newUserModel.setContact(uModel.getContact());
String email = new String(uModel.getEmail().getBytes("UTF-8"));
System.out.println(uModel.getEmail() + " encoded email = " + email);
newUserModel.setEmail(uModel.getEmail());
newUserModel.setFname(uModel.getFname());
newUserModel.setLname(uModel.getLname());
newUserModel.setEmailTemplate(uModel.getEmailTemplate());
String current_Date = new SimpleDateFormat("MM/dd/yyyy").format(new Date());
newUserModel.setCurrentDate(current_Date);
Gson gson = new GsonBuilder().setDateFormat("MM/dd/yyyy").create();
user = gson.toJson(newUserModel);
System.out.println("user = " + user);
}
return user;
}
}
====================postlisting.jsp====================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html>
<%
String direction = (String) request.getAttribute("data");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charaset=UTF-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<fieldset style="border: none;">
<center>
<legend>
<b><"label.extruder.myProfile.newListing.basicinfo"/></b>
</legend>
<table id="f1" style="text-align: justify;">
<tr>
<td ><"label.extruder.myProfile.newListing.cntName"/>:*</td>
<td ><input type="text" style="width: 100px;" id="cName"/></td>
</tr>
<tr>
<td><"label.extruder.myProfile.newListing.cntEmail"/>:*</td>
<td><input type="text" id="cEmail" style="width: 100px;"/></td>
</tr>
<tr>
<td><"label.extruder.myProfile.newListing.cntNo"/>:*</td>
<td><input type="text" id="cNo" style="width: 100px;"/></td>
</tr>
<tr>
<td><"label.extruder.myProfile.newListing.dateL"/>:*</td>
<td><input type="text" id="dateL" style="width: 100px;"/></td>
</tr>
<tr>
<td><"label.extruder.myProfile.newListing.dateA"/>:*</td>
<td><input type="text" id="dateA" style="width: 100px;"/></td>
</tr>
<tr>
<td><"label.extruder.myProfile.newListing.rent"/>:*</td>
<td><input type="text" id="rent" style="width: 100px;" /></td>
</tr>
</tr>
</table>
</center>
</fieldset>
</div>
</body>
</html>
任何机构都可以解决这个问题吗?