• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Login Module for Online Test Application

 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i am developing small demo of Online testing.
Though username exist in Database, it shows "User Doesn't Exist"...!

Here,
"login.jsp" is file containing form that will get Username and Password from USER.
login_Servlet is controller that will get username and password from login.jsp and also give Username to Model class "login_Model" for getting all other informations like; Password, UserLevel(1-admin , 0-student), username.

If Username from Form of Jsp page and UserName from Database will be same than user will be authorized and will be given further entry to application part.

Databse name:: test_center
Table Name:: test_user
Database fields:
-------------------
u_id --> int ---- PK , Not null
u_name --> varchar ---- not null , unique
u_password --> varchar ----notnull
u_level --> varchar ----notnull (values are either 0 or 1)


login.jsp
----------


login_servlet.java (Controller)
--------------------------------------------


login_Model.java (Model)
--------------------------------------
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all change this:

public void setU_name1(String u_name) {
this.u_name1 = u_name1;
}

And do not repeat the code:

else{
error ="User Doesn't Exist..!";
request.setAttribute("err",error);
RequestDispatcher red = request.getRequestDispatcher("login.jsp");
red.forward(request, response);
}

if(pass.equals(Pass_DB))
{
if(Level_DB.equals("1"))
{
RequestDispatcher red = request.getRequestDispatcher("CreateTest.jsp");
red.forward(request, response);
}
else if(Level_DB.equals("0"))
{
RequestDispatcher red = request.getRequestDispatcher("StudentTest.jsp");
red.forward(request, response);
}

Instead of repeating the code you can do as follows:

String responsepage="";

Reassign the value of error in each if-else block and then write only one request.setAttribute("err",error); statement.
Reassign the value of responsepage at each condition, and use request.getRequestDispatcher(responsepage).forward(request,response);

hope this may help you.
 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gopakumar kiing wrote:first of all change this:

public void setU_name1(String u_name) {
this.u_name1 = u_name1; // this.u_name1 = u_name;
}


And do not repeat the code:

else{
error ="User Doesn't Exist..!";
request.setAttribute("err",error);
RequestDispatcher red = request.getRequestDispatcher("login.jsp");
red.forward(request, response);
}

if(pass.equals(Pass_DB))
{
if(Level_DB.equals("1"))
{
RequestDispatcher red = request.getRequestDispatcher("CreateTest.jsp");
red.forward(request, response);
}
else if(Level_DB.equals("0"))
{
RequestDispatcher red = request.getRequestDispatcher("StudentTest.jsp");
red.forward(request, response);
}


Instead of repeating the code you can do as follows:

String responsepage="";

Reassign the value of error in each if-else block and then write only one request.setAttribute("err",error); statement.
Reassign the value of responsepage at each condition, and use request.getRequestDispatcher(responsepage).forward(request,response);

hope this may help you.
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ,

Was it helpful to you?
did you solve the problem?

 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gopakumar kiing wrote:Hey ,

It was helpfulll

And it had only one minor of minor mistake that "Space" between "us _ er"
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good...

I also saw it first and i thought it might be some problem with this clipboard.
(You can see the same for getter methods of ulevel & password in the above code.)

Cool..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic