好友
阅读权限10
听众
最后登录1970-1-1
|
这是表单<form role="form" method="post" class="input-length">
<div class="form-group">
<input type="text" id="username" class="form-control input-bottom-length" name="username"
placeholder="用户名">
<input type="password" id="password" class="form-control input-bottom-length" name="password"
placeholder="密码">
</div>
<a href="#" class="a-right-length">忘记密码</a><a href="#" class="">注册</a>
<button class="btn form-control btn-info" onclick="send()" id="submits">提交</button>
</form>
这个是请求<script type="text/javascript">
var username = document.getElementById("username");
var password = document.getElementById("password");
var user = {"username": username, "password": password};
function send() {
$.ajax({
async: true,
url: "/blogs_war/login",//URL没有变意味着我用同一个servlet哦,演示本例的时候吧之前的都注释掉了
data: JSON.stringify(user),
processData: false,
success: function (data) {
alert(data);
},
error: function (e) {
alert(e);
}
})
}
</script>后端无响应,附上代码,求助@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/json;charset=UTF-8");
BufferedReader reader = new BufferedReader(request.getReader());
String json = reader.readLine();
List<Object> list = JSONArray.parseArray(json);
System.out.println(list.get(0));
System.out.println(list.get(1));
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username + "###" + password);
Servce servce = new Servce();
if (servce.login(response, username, password)) {
request.getRequestDispatcher("/danshbod.html").forward(request, response);
} else {
response.getWriter().write(servce.getJson().toString());
servce.getJson().remove("message");
}
}
}
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|