It's my first project, want to create login servlet for employee.
i have created jsp but not getting the logic to create Servlet for the same.
The jsp code is as follows :
Habeeb Shaikh
Ranch Hand
Joined: Nov 23, 2008
Posts: 40
posted
0
Hi mohini,
What you want to say exactly.Do you want to create a servlet ? how to use it? or anything else?
Mohini Dhanaskar
Ranch Hand
Joined: Mar 27, 2012
Posts: 52
posted
0
i want to create a login servlet for the employee.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
What, exactly, should this servlet do? No sense thinking about details (or even code) unless and until the requirements are clear.
Mohini Dhanaskar
Ranch Hand
Joined: Mar 27, 2012
Posts: 52
posted
0
Sorry Sir for inconvenience,
There is a jsp called employee login in which the employee has to enter empid and password.
which has been check from database table EmpRegistration.
If the employee is registered and valid ,EmailFormat jsp will appear or else LoginError.jsp will appear.
hope this has given you some idea.
Habeeb Shaikh
Ranch Hand
Joined: Nov 23, 2008
Posts: 40
posted
0
hi mohini, do not called me as sir,
1. Create a class LoginServlet.
2. Create 2 setter and getter method for empname and password.
3. In getter method you can write your any validation code like emp does not exit if it is not in database or any your simple arraylist.
4. Import LoginServlet into your .jsp class
5 Set value attribute of empname text field by using loginServlet.getEmpname()
I hope you understand it.let me know if any difficulty.
Mohini Dhanaskar
Ranch Hand
Joined: Mar 27, 2012
Posts: 52
posted
0
thank you, i will try and let you know.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
Habeeb Shaikh wrote:
1. Create a class LoginServlet.
2. Create 2 setter and getter method for empname and password.
3. In getter method you can write your any validation code like emp does not exit if it is not in database or any your simple arraylist.
4. Import LoginServlet into your .jsp class
5 Set value attribute of empname text field by using loginServlet.getEmpname()
A servlet is a servlet, not a backing (or model) bean. It does not need getters and setters, and it should definitely not be used in a JSP page. The basic steps of the servlet code are: retrieve username and password from the request, use them to check for validity against the DB, and depending on that redirect to either of the JSP pages. Which of these steps are you having difficulties with?
Also note that you need to fix your HTML - while there are several input fields, there is no actual <form ...> ... </form> tag. Without that there'S no way to specify the URL of the servlet that the form should be submitted to, or that the HTTP method to be used is a POST.
Habeeb Shaikh wrote:hi mohini, do not called me as sir,
1. Create a class LoginServlet.
2. Create 2 setter and getter method for empname and password.
3. In getter method you can write your any validation code like emp does not exit if it is not in database or any your simple arraylist.
4. Import LoginServlet into your .jsp class
5 Set value attribute of empname text field by using loginServlet.getEmpname()
I hope you understand it.let me know if any difficulty.
Why should a servlet have a setter, getter methods. Servlet is a controller. What is the need of importing a servlet in jsp? You should never embed java code in jsp it's a very old practice and not at all recommended these days, use el/jstl/custom tags etc. Your process flow should be like this
1. Create a login page which has two textboxes to enter user id and password
2. The submit action of this page is mapped to a servlet
3. Servlet retrieves the value of those two boxes using getParameter method of request object.
4. You do the required validation in the servlet or using some helper classes.
5. Based on the validity of user credentials you redirect the user to the specific jsp/html page.
You should never compare a String object like this
it should have been (use methods of String class)
Mohini,
What you are saying is little confusing. You said that it's displaying the login error page, that means it's being redirected from the servlet, right, and again you are saying nothing happens if you click on the submit button.
Prashant Chindhade
Ranch Hand
Joined: Jan 19, 2011
Posts: 77
posted
0
Swastik Dey wrote:prashant,
You should never compare a String object like this
it should have been (use methods of String class)
Mohini,
What you are saying is little confusing. You said that it's displaying the login error page, that means it's being redirected from the servlet, right, and again you are saying nothing happens if you click on the submit button.
ya thanks for that. i will follow this now on.
Mohini Dhanaskar
Ranch Hand
Joined: Mar 27, 2012
Posts: 52
posted
0
Swastik Sir,i mean to say that
if i run only that servlet alone it is displaying LoginError.jsp.
Bu when i run the EmployeeLogin jsp that time after clicking signin(submit) button there is
no respond.
By this what I understand is, when you are hitting the mapped url of the servlet in the browser you are getting the login error page, that may be possible because it may not be getting the query parameter values. As far as the second problem is concerned, probably we need to see the code of your login page, i.e form action, and the web.xml file to know whether the servlet mapping is correct or not.
Not to spoil the party, but the technical term for web applications with Login Servlets in them is "hacked", "pwned" or "exploited". I really wish that J2EE books wouldn't use Login Servlets as demonstrators. Java has a much more secure way of doing logins that doesn't require any user-written code at all.
Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.