I need to pull a line from request'a, which I passed to the servlet using an ajax request. Here is the ajax request code:
$(document).ready(function(){ $("#login-button").click(function(){ var userPassword = $("input#userPassword").val(); var userLogin = $("input#userLogin").val(); var dataString = "log_in " + userLogin + " " + userPassword; $.ajax({ type: "POST", url: "http://localhost:8181/library/login", data: dataString, dataType: "text", success: function(data) { alert("Welcome!"); }, error: function(jqXHR,textStatus,errorThrown) { alert("Wrong login or password"); } }); }); });
And I need to pull the dataString
from the servlet side. How will it look like? Because in the following code, request.getQueryString
always turns out to be null
.
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("text/html;charset=UTF-8"); SocketConnection.output.println(request.getQueryString()); String string = SocketConnection.input.readLine(); if(string.equals("1")) { RequestDispatcher rs = request.getRequestDispatcher("workshop.html"); rs.forward(request, response); } else if(string.equals("2")) { RequestDispatcher rs = request.getRequestDispatcher("library.html"); rs.forward(request, response); } else { out.println("Error"); } }