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



Home Answers Viewqa JSP-Servlet Login With Drop Down, Having Departments in different table
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Prem Sagar
Login With Drop Down, Having Departments in different table
0 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet


Hi all,

I am doing a project using JSP. My Issue is..... I have two departments name Customs and Accounts in the database with different tables. I have designed the HTML page in such a way the I have a drop down list consisting of Customs and Accounts. I have user accounts of both the departments.

Now, my intention is to select the department from the drop down box and then login to the page.

I have a drop down list box with Customs and Accounts..A Username and a Password field.Now want to login to the page by selecting the drop down box. Suppose the Customs username is 1001 and Accounts Username is 1002. and password is abcd.

In my project I have different departments say, Customs in one table and Accounts in other table. The code provided is having the departments in the same table. Bcoz as per the SQL Query select * from login where username='"+user+"' and password='"+pass+"'and department='"+dep+"' the departments is in the same table. And my issue is I want to login using different departments Customs and Accounts which are in different tables and as soon as I login I have to get individual page of Customs and Accounts.

Suppose In Customs, I have a DEPTID DEPTNAME DEPTHEAD PASSWORD ---- THIS IS ONE TABLE THE SAME LIKE ACCOUNTS. Now I want to login when I select department from the drop down list. Since I cannot populate the departments name from each table into drop down I use Select tag and declare as CustomsDept and AccountsDept

Please provide me the code on how to login using the drop down box and the Username and passwords must match with the Database during Login. One of my friend suggest me to use if(option.equals) condition for LOGIN...Please provide me the code for the above senario.....I'll be grateful to you forever.

Thank You Very Much

Prem Sagar.

Code provided:

1)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>Select Department: </td>
<td>
<select name="dep">
<option value="-1">Select</option>
<option value="Customs">Customs</option>
<option value="Accounts">Accounts</option>
</select>
</td></tr>
<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="Login"></td></tr>
</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>
<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
String com=request.getParameter("dep");
 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+"'and department='"+dep+"'");
       int count=0;
       while(rs.next()){
       count++;
      }
      if(count>0){
       out.println("welcome "+user);
       }
      else{
       response.sendRedirect("login.jsp");
      }
    }
    catch(Exception e){
    System.out.println(e);
}
%>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Login With Drop Down, Having Departments in different table
Login With Drop Down, Having Departments in different table  Hi all... the departments name from each table into drop down I use Select tag and declare... is to select the department from the drop down box and then login to the page. I
Login With Drop Down
Login With Drop Down   Hi all, I am doing a project using JSP. My... the departments. Now, my intention is to select the department from the drop down box and then login to the page. I have a drop down list box with Customs
Advertisements
display table details when selecting table name in drop down liat
display table details when selecting table name in drop down liat  Hello, Am having problem in my project... i want to retrive the data from mysql... of tables from the database to the dropdown list... if i select the particular table
jsp login code ... when username , drop down box and password is correct
jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box value is correct.... the drop down box values should be retrieved from database
drop down
drop down  how can i add data from choice/dropdown component of java awt to myaql table
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
Add values of drop down menu( select option) to mysql table
Add values of drop down menu( select option) to mysql table   Here is my code <?php echo $row['valveName'].'<td>'.$row['valveId'].'<td>'; echo '<select name="onoff">'; echo '<
drop down menu
drop down menu  drop down menu using html
Drop down menu
Drop down menu  I have drop down list of some 14 links which links to the table,If i click each link the table should display below the link and again if i click the link the table should not appear. please help me
Drop down menu
Drop down menu  I have created a drop down list of links which links to a table but if i click the link the table display in the other page i want to display it in the same page.Please tell me the solution
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
DropDown Department Login
down box and then login to the page. I have a drop down list box with Customs... is having the departments in the same table. Bcoz as per the SQL Query select * from...+"' the departments is in the same table. And my issue is I want to login using
Drop Down reload in IE
Drop Down reload in IE  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down ( which is date) automatically
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's field....  my project has customer registration and company registration... in customer registration page and should be shown in drop down box in front end
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
validation for drop down list
validation for drop down list  Hi all I have a form, it contain 12 drop down list. Each drop down has 1 to 5 values,i need to validate this form. the following condition should be true. 1.you can choose only 3 times 5 value. 2
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select a particular value from one the other list is developed accordingly..depending
dynamic drop down
dynamic drop down   I have created 2 drop downs in jsp.1... into the designation drop down (use jsp+javascript+servlet) reply soon   1..., create tables dept and designation: CREATE TABLE `dept
Get values in drop down list
Get values in drop down list  Pls provide me jsp code to get values in drop down list from another table's field. my project has customer... in drop down box in front end..... pls provide me code.. thanx
Ajax drop down and textbox
Ajax drop down and textbox  hie frnds I have a dropdown menu in the 3 options(1,2,3) are there if i choose 1 then I should get 1 text box if i select... in advance............   Here is an ajax example which is having a drodown
Dependent drop down list
Dependent drop down list  hi,i am trying to design a form on which 2 dependent drop down list is used my code is successful but when i select class from first drop down list all the data get lossed means the value entered
Drop down combos
Drop down combos  Hi.. How to write a javascript for linked combo dropdown boxes.   <html> <h2>ComboBox</h2> <script language="javascript"> var arr = new Array(); arr[0] = new Array("-select
Add/Remove Rows Dynamically with drop down list in html table using php
Add/Remove Rows Dynamically with drop down list in html table using php  Here Is My Code. I want to give and get the id of drop down list. Can Anyone...;table border="1" id="tblSample"> <tr> <
drop down php mysql - PHP
drop down php mysql  PHP Script required to show the similar drop down item in each menu without refreshing the page. Is it possible if yes how
drop down box - JSP-Servlet
drop down box  when i enter some letter in the input box,the corresponding words of that particular letter must be displayed below as a list from the data base in the same input box as drop down. Thanks&Regards, VijayaBabu.M
Dependant & dynamic drop down list
Dependant & dynamic drop down list  I don't know this should be in this or AJAX forum. I have one dynamic drop down list from data base (working... on the values selected by user in first drop down list. How to achieve this ?   
Drop down list from database
Drop down list from database  Hi, Can I know how do we get the drop down list from database? Eg: select country--select state--select district--so..., we have created two database tables: CREATE TABLE `country
jsp drop down-- select Option
jsp drop down-- select Option  how to get drop down populated dynamically   Hi Friend, Create table country(country_id,country...)country CREATE TABLE country ( countryid bigint(30) NOT NULL auto
Drop Table
Drop Table       Drop Table in SQL get rid of an object or table from the database. Using a drop Query... from database. The Drop table cannot get it back, once you run the drop Query
JSP Dependent Drop Down Menu
JSP Dependent Drop Down Menu  Hey Guy/Gals! I need someone help to guide me in creating a drop down menu, where the first menu affects the second menu and it's selection. So in my database I have a category table that has a ID
Select functionality of drop down list - Struts
have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box...Select functionality of drop down list  Hi, I have to write a code(in struts application) in which if user select HIDE from the drop down list
 

 

 

DMCA.com