我对所有这些东西都很陌生,但希望你们能帮助我了解它是如何工作的。我得到了一个带有 field 的表格。我如何从客户端获取数据?正在寻找一些信息,但找不到。
<form action="/login" method="POST">
<fieldset>
<legend>MemberId</legend>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="txt_memberid" class="control-label">MemberId</label>
</div>
<div class="col-lg-8 col-sm-8">
<input class="form-control" id="txt_memberid" name="txt_memberid" placeholder="MemberId" type="text" value="" />
<span class="text-danger"></span>
</div>
</div>
</div>
<legend>Login</legend>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="txt_username" class="control-label">Username</label>
</div>
<div class="col-lg-8 col-sm-8">
<input class="form-control" id="txt_username" name="txt_username" placeholder="Username" type="text" value="" />
<span class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="txt_password" class="control-label">Password</label>
</div>
<div class="col-lg-8 col-sm-8">
<input class="form-control" id="txt_password" name="txt_password" placeholder="Password" type="password" value="" />
<span class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 col-sm-12 text-center">
<input id="btn_login" name="btn_login" type="submit" class="btn btn-default" value="Login" />
<input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-default" value="Cancel" />
</div>
</div>
</fieldset>
get("/login", (request, response) -> {
ConsoleLog.consoleLog(log, request);
HashMap model = new HashMap();
model.put("content", new VelocityTemplateEngine().render(new ModelAndView(new HashMap(),"templates/form_login.vtl")));
return new ModelAndView(model, "templates/base.vtl");
}, new VelocityTemplateEngine());
post("/login", (request, response) -> {
ConsoleLog.consoleLog(log, request);
Integer memberId = -1;
String username = "";
String password = "";
try {
username = request.queryParams("txt_username");
password = request.queryParams("txt_password");
memberId = new Integer(request.queryParams("txt_memberid"));
} catch (Exception e) {}
log.info("MemberId="+memberId+" UserName="+username+" Password="+password);
if (new MemberDAO().isAuth(new Auth(username,password,memberId))) {
request.session(true);
request.session().attribute("txt_memberid", memberId);
request.session().attribute("txt_username", username);
}
return "process";
});
如果我发送表单 (method=get) - 一切正常 request.queryParams(XXXX) 如果我发送表单 (method=post) - 在 request.queryParams - 没有
也许有人知道我应该在 POST 请求中做什么?