當前位置:編程學習大全網 - 網站源碼 - 在springMVC中如何用ajax實現登錄驗證(頁面局部刷新提示用戶名或密碼錯誤)

在springMVC中如何用ajax實現登錄驗證(頁面局部刷新提示用戶名或密碼錯誤)

ajax方法:

$.ajax( {

type : "POST",

url : "/home/user/login.htm", //訪問路徑

data : {name: name, title: title}, //參數

success : function(msg) {

if (msg == 1) {

} else {

}

},

error:function(msg){

alert("程序出錯,請聯系管理員");

}

});

java類方法:

@RequestMapping("user/login.htm")

public String getAddGroupsAjax(String name,String title) throws Exception{

HttpServletResponse response = getResponse();

response.setContentType("text/html;charset=UTF-8");

PrintWriter pw = null;

//方法處理,最後返回壹個字符竄,來判斷是成功還是失敗了

try {

pw = response.getWriter();

pw.print(str);

} catch (IOException e) {

//錯誤處理

}finally{

pw.close();

}

return null;

}

以上最少需要妳懂壹些springMVC,不然的話我也沒辦法

  • 上一篇:hive讀取orc文件行數
  • 下一篇:淘寶會員送什麽音樂會員
  • copyright 2024編程學習大全網