aspose file tools*
The moose likes JSP and the fly likes Login Module for Online Test Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Login Module for Online Test Application" Watch "Login Module for Online Test Application" New topic
Author

Login Module for Online Test Application

Rushi Patel
Greenhorn

Joined: Sep 14, 2011
Posts: 17
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

Joined: Jan 15, 2011
Posts: 72

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.


Thanks & Regards
Gopakumar
Rushi Patel
Greenhorn

Joined: Sep 14, 2011
Posts: 17
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

Joined: Jan 15, 2011
Posts: 72

Hey ,

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

Rushi Patel
Greenhorn

Joined: Sep 14, 2011
Posts: 17
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

Joined: Jan 15, 2011
Posts: 72

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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login Module for Online Test Application