Hello!
I'm trying to write a simple web app based upon applet-servlet communication!
I have a couple of
servlets the first of which lets the user to log into the database
The login part of the
applet is the following
//on a button click
username = userNameFld.getText().trim();
password = passFld.getText().trim();
try{
loginParameters = "?username=" + username + "&" + "password=" + password;
loginURL = new URL(protocol, hostName, port, "/servlet/AuthenticationServlet/" + loginParameters);
connection = loginURL.openConnection();
connection.setDoInput(true);
connection.setUseCaches(false);
ObjectInputStream ois = new ObjectInputStream(connection.getInputStream());
Request request = (Request) ois.readObject();
ois.close();
String access = request.getAuthorization();
if(!access.equals("success")){
userNameFld.setText(null);
passFld.setText(null);
messageLabel.setText(access);
connection = null;
}else{
//allow further actions
}
}catch(Exception e){
userNameFld.setText(null);
passFld.setText(null);
messageLabel.setText(e.getMessage());
connection = null;
}
The servlet part is the following
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection connection = null;
String username = null, password = null, access = null;
username = request.getParameter("username");
password = request.getParameter("password");
Request request = new Request();
try{
//Here go to the database and fill the request object
ObjectOutputStream ous = new ObjectOutputStream();
ous.writeObject(request);
ous.flush();
}catch(Exception e){
}
Each user has a different account so I cant use connection pooling here (although it can be created dinamically but
I dont see it suitable in my case)!
In my case the connection to the database should be alive only for the duration of the doGet() method!
I'm new to servlets and I dont know how to make so that, for example, the doGet() method of the above servlet
can handle multiple requests comming at the same time.
Any suggestion would be of much help!
Please help!
Thank you very much, Feadi!