
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..... please provede me codes for that..... thnk u

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>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Select Company: </td><td>
<select name="com">
<%
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");
while(rs.next()){
%>
<option value="<%=rs.getString("company")%>"><%=rs.getString("company")%></option>
<%
}
%>
</select>
</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("com");
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 company='"+com+"'");
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);
}
%>

thank u... the half..i.e the first program works.... the value is retrieved from database into combo box..... but the validation is not happening..... the all three username , passwrod and company name are corect but its showing as wrong..... i dont know how to check the combo box selected value.... pls help me.... thnx
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.