本文實(shí)例講述了ajax發(fā)送GET請(qǐng)求,然后通過(guò)jsp頁(yè)面來(lái)接收處理的實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
這里用一個(gè)實(shí)例演示Ajax發(fā)送get請(qǐng)求,實(shí)例具體要求為一個(gè)注冊(cè)頁(yè)面,當(dāng)用戶填寫(xiě)完用戶名稱時(shí),該輸入框失去焦點(diǎn)后會(huì)通過(guò)Ajax向后臺(tái)發(fā)送驗(yàn)證信息,如果用戶名不是admin則通過(guò)驗(yàn)證,否則不通過(guò)驗(yàn)證。
servlet>
servlet-name>LoginServlet/servlet-name>
servlet-class>login.LoginServlet/servlet-class>
/servlet>
servlet-mapping>
servlet-name>LoginServlet/servlet-name>
url-pattern>/servlet/LoginServlet/url-pattern>
/servlet-mapping>
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charaet=UTF-8");
PrintWriter out = response.getWriter();
String name=request.getParameter("username");
System.out.println(name);
if(name.equals("admin"))
out.print(false);
else
out.print(true);
out.flush();
out.close();
}