ext 、ajax和servlet结合的一个小例子

extjs:

Ext.onReady(function(){
Ext.get("btnSubmit").on('click',function(){
var content =Ext.get("com_content").getValue();
if(content==""){
Ext.MessageBox.alert("内容不能为空!");
}
else{
Ext.Ajax.request({
url:'MessageBoxServlet',
params: {content :content} ,
Method:"post",
success: function(response){
//var message = request.responseText;
var message = response.responseText;
Ext.get("CommentList").dom.innerHTML=response.responseText;
//Ext.MessageBox.alert("信息",message);
},
failure: function(response){
Ext.MessageBox.alert("错误!"+response.status);
}
});
}
})
})


servlet:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("utf-8");
String content = request.getParameter("content");

//response.getWriter().write(content);
PrintWriter out = response.getWriter();
out.print(content);
out.flush();
out.close();
}

 

posted @ 2012-03-09 14:26  合肥房屋托管  阅读(670)  评论(0编辑  收藏  举报