I am trying to make login validation in using httpClient and getting infinite loop on server side.More explanation will be after code. here is my server side code
public void doPost(HttpServletRequest req, HttpServletResponse resp)
while(true){
String user_name = req.getParameter("username");
String password = req.getParameter("password");
System.out.println("User name and password is "+user_name +" paswword is "+password);
resp.setContentType("text/plain");
PrintWriter writer = resp.getWriter();
if(user_name.equalsIgnoreCase("haseeb")){
System.out.println("valid user name");
writer.write("welcome");
//writer.flush();
break;
}
else{
writer.write("unknown User");
System.out.println("unknown user name");
writer.flush();
continue;
}
}//End of while loop
} //End of doPost Method
from client side i am trying to login, if login is invalid the server will return “unknownUser” after that client will send again request to login if login is valid the loop will break. on server side i am getting infinite loop and server is processing on first request parameters again and again and again….!!! If any one want i can post my client side code for further assistance, you can ask for it on comments section..Thankyou
You don’t seem to understand how HTTP requests work.
The user’s browser sends a request to the server asking for the login page, the server responds with the HTML and that response ends there. Then, the user validates his credentials, causing the browser to send a new request, and the server responds with either the page after the login, or the login page again and a message indicating that the credentials did not match, but in both cases the response ends there again. HTTP connections are not kept, it’s just a series of requests and responses in separate connections.
So you don’t use a loop, you just send the appropriate HTML back, once per request.
This still holds even if the user’s application is a desktop application and not a browser, as long as it uses HTTP as its transport. You can’t resubmit data using the same request, at least not if you use the
HttpServletRequest/HttpServletResponseparadigm.