我的 .js 文件
function call() {
var val1;
var val2;
var b2 = new goog.ui.Button();
b2.decorate(goog.dom.getElement('but'));
goog.events.listen(b2, goog.ui.Component.EventType.ACTION,
function(e) {
val1 = (goog.dom.getElement('liun').value);
val2 = (goog.dom.getElement('lipw').value);
var request = new goog.net.XhrIo();
var res;
goog.events.listen(request, "complete", function(e){
var xhr = /** @type {goog.net.XhrIo} */ (e.target);
res = xhr.getResponseText();
if(xhr.getResponseText() == "true")
{
goog.dom.getElement("sp1").innerHTML = ("Hi Welcome");
}
else
{
goog.dom.getElement("sp1").innerHTML = ("Invalid Username or Password");
}
});
var url = 'mylogin?username='+val1+'&password='+val2;
request.send(url, "GET");
});
}
我的小服务程序
public class mylogin extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
String uname = ((req.getParameter("username")).trim());
String pword = ((req.getParameter("password")).trim());
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
System.out.println("" + uname + " " + pword);
String tof;
if((uname.equals("arjun"))&&(pword.equals("daglur")))
{
tof = "true";
}
else
{
tof = "false";
}
System.out.println(tof);
out.write(tof);
out.close();
}
}
当我第一次点击发送时,它没有被发送。第二次打一个电话。第 3 次拨打 2 次电话,第 4 次拨打 3 次电话。在 jsp 中单击时调用 call()。