Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet lOGIN according to der roles

Have Programming Question? Ask it here!
 
 
 


ranireddy
lOGIN according to der roles
2 Answer(s)      2 years and 2 months ago
Posted in : JSP-Servlet


how to login a user according to roles and page will should be same content will be different


Advertisement
View Answers

February 21, 2012 at 3:22 PM


1)index.jsp:

<a href="login.jsp">User Login</a>&nbsp&nbsp&nbsp&nbsp<a href="adminPage.jsp">Admin Login</a>

2)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
<%String msg=request.getParameter("msg");
if(msg!=null){
    %>
<label><font color="red"><%=msg%></font></label> 
<%
}
    %>

3)check.jsp:

<%@page import="java.sql.*"%>

<%
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("login.jsp?msg=Invalid Username or Password");
          }
%>


February 21, 2012 at 3:23 PM


continue..

4)adminPage.jsp:

<html>
<title>Admin login Page</title>
<head>
<script language="JavaScript">
function isProper(string) {

if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}

function validateForm(theForm){
if(theForm.userid.value==""){
//Please enter accountholder
alert("Enter the User Name.");
theForm.userid.focus();
return false;
}

if (isProper(theForm.userid.value) == false) {
alert("Please enter a valid User Name.");
theForm.userid.focus();
return false;
}

if(theForm.userid.value.length > 20) {
alert("Maximum 20 characters allowed for 'First Name'.")
theForm.userid.focus() ;
return false;
}

if(theForm.password.value==""){
//Please enter accountholder
alert("Enter the password.");
theForm.password.focus();
return false;
}

if (isProper(theForm.password.value) == false) {
alert("Please enter a valid password.");
theForm.password.focus();
return false;
}

if(theForm.password.value.length > 20) {
alert("Maximum 20 characters allowed for 'Password'.")
theForm.password.focus() ;
return false;
}

return true;
}
</script>
</head>
<body>
<H1>Admin login Page</H1>
<form method="POST" action="adminPageAction.jsp" onsubmit="return validateForm(this);">

<table border="1" ALIGN="LEFT" cellspacing="0" cellpadding="0" width="50">
<tr>
<td width="25%"><b>User-Id:</b></td>
<td width="25%">
<input type="text" name="userid" size="20">
</td>
</tr>
<tr>
<td width="25%"><b>Password:</b></td>
<td width="25%">
<input type="password" name="password" size="20">
</td>
</tr>
<tr>
<td>&nbsp</td>
<td>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

5)adminPageAction.jsp

<%@ page language="java" import="java.sql.*,java.io.UnsupportedEncodingException,java.security.MessageDigest,sun.misc.BASE64Encoder,sun.misc.CharacterEncoder,java.security.MessageDigest" %>


<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String userid=request.getParameter("userid");
String password=request.getParameter("password");

MessageDigest d = MessageDigest.getInstance("SHA");
d.update(password.getBytes("UTF-8"));
byte raw[] = d.digest();
String hash = (new BASE64Encoder()).encode(raw);
System.out.println(hash);

con.close();
out.println("Successfully");
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>


Related Tutorials/Questions & Answers:
lOGIN according to der roles
lOGIN according to der roles  how to login a user according to roles...(); ResultSet rs=st.executeQuery("select * from login where username='"+user...: <html> <title>Admin login Page</title> <head> <
User LogIn According to Role
User LogIn According to Role  User login According to role but output will be always displayed in a single page.. but content will change according role
Advertisements
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit Here Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE  I HAVE A PROBLEM IN PHP CODING PLS HELP ME PROBLEM IS THAT I WANT DIFFERENT PAGES TO VIEW FOR DIFFERENT USERS WHEN THEY LOGIN ACCORDING TO THEIR ROLE IN DATABASE
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
Arrange strings according to their length
Arrange strings according to their length In this section, you will learn how to arrange the strings according to their length in ascending order. For this, user is allowed to enter three strings according to their choice. The method
login page
login page  code for login page
Change language according to the locale
Change language according to the locale  ... language according to the locale. In the code given below we have changed language according to the locale. Methods used in this example are described below
Login page
Login page  how to create Login page in java
login page
login page  How to login as different user in php
login-logout
login-logout  how to do login and logout using session in php
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information.
  Match EJB roles.... EJB Overview Next     Match EJB roles... roles defined : Bean Provider The Bean
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user
Login Program
Login Program  Login program in struts to set username & password in session. and this session is available in all screens for authentication..., Please read it at: Login/Logout With Session Accessing Session Object Thanks
login box
login box  class file for password and conform password and how it connected to database
login page
login page  pls say how to create a login page in jsp and mysql using netbaens   Hi Friend, Please visit the following links: http://roseindia.net/jsf/netbeans/index.shtml http://roseindia.net/jsp/loginbean.shtml
login data
login data   Hiiii Sir I am doing banking project on Asp.net i have... the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance
login data
login data  Hiiii Sir I am doing banking project on Asp.net i have... the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance
Login Form
Login Form  I have 8 jsp pages.Each of them has three columns:Left... of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so
Login Form
Login Form  I have 8 jsp pages.Each of them has three columns:Left... of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so
JSP LOGIN
JSP LOGIN  sir....i have two user types usercategory and user and both user have userid and password in two different table and now i am making login page for which i have to retrieve usertype,userid and password from two
login page
login page  hi i'm trying to create login page using jsp. i get... <h1>Login Example!</h1> USER NAME <input name="uname...="text"/><br> <br> <input name="Login" type="submit" value
login and logout
login and logout   > > > > hi, > > I have created two pages, one is home.jsp and another is welcome.jsp. In my home.jsp code i > created a login form and after submitting
Write a program to display grade message according to the marks
Write a program to display grade message according to the marks  pls give d answer how to Write a program to display grade message according to the marks     Write a program to display grade message according
Login Project
Login Project  why should get the following compile error LoginForm log=(LoginForm)form. this will get when compile LoginAction class please give suggestion byee   make sure public class LoginAction extends Action
login in jsp
login in jsp  i need code for login which is verify the registeration... and otherwise show the failed message.   JSP Login Form 1)login.jsp: <html>...(); ResultSet rs=st.executeQuery("select * from login where username='"+user
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components...() { setTitle("Login Form"); setLayout(null); label1 = new JLabel
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components...; LoginDemo() { setTitle("Login Form"); setLayout(null); label1 = new
according to me its ok but is calculating wrong values in
according to me its ok but is calculating wrong values in   program to calculate roman numbers .....i.e roman number calculator import java.util.*; import java.io.*; class romancalci { public static void main(String
Login - Struts
Struts Login page  I want to page in which user must login to see that page. I can do that simple but he/she know that page URL,he/she can simplely type that url... Login Page after logging that page must return to my page.please
swing login code
swing login code  code for the login form
coding for login page
coding for login page  coding for login page
login example
login example  1.Loginpage.jsp <%@ page language="java...-Type" content="text/html; charset=windows-1256"> <title>Login...; public static UserBean login(UserBean bean) { //preparing
login example
login example  1.Loginpage.jsp <%@ page language="java...-Type" content="text/html; charset=windows-1256"> <title>Login...; public static UserBean login(UserBean bean) { //preparing
Advertisements
 

 

 

DMCA.com