我正在使用下面的ajax来解析从servlet到jsp的数据(工作正常)
function myfunction() {
var tableColms = {};
tableColms.tableName = $('#tableName').val();
var rowcollection = [];
$('#tableContent').find('tr').each(function(){
var row = {};
row.colName = $(this).find('input[type="text"]').val();
row.colType = $(this).find('select').val();
rowcollection.push(row);
});
tableColms.tableColomns = rowcollection;
console.log(tableColms);
myajax(tableColms);
}
function myajax(jsonParam){
$.ajax({
url: "table",
type: "POST",
data: "JSON="+JSON.stringify(jsonParam),
datatype: "application/json",
success: function(data){
window.location.href="/CreateDatabase1/getDynamicData.jsp";
},
error: function(data){
alert('Exception Occured, '+data);
}
});
//现在我将这个jsp ajax发送到bellow java servlet包
com.jwt.servlet;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Gson g = new Gson();
tableCls tableDt = g.fromJson(request.getParameter("JSON"), tableCls.class);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String table = tableDt.tableName;
request.setAttribute("name", table);
request.getRequestDispatcher("/getDynamicData.jsp").forward(request, response);
错误__>>>现在页面加载我在另一个jsp上发送此请求调度程序,我没有得到任何数据。
<h3> Table name is <%= request.getAttribute ("name") %></h3>
我正在Eclipse上进行上述项目但是在页面加载时我无法获得来自(Forward Requestdispatcher)的任何类型的数据。