Create a form of user Login in JSP, that accepts the user
name and password from user and authenticate it with user
names and passwords stored in database.

(Plz provide me answer immediately)

Answer Posted / amit2009mca

first you should to create a jsp
like login.jsp

<%@page language="java"%>
<html>
<head>
<title>fill form</title>
<body>
<form action ="loginservlet.java" mrthod=post>
<input type =text ,name=username ,value="">
<imput type =password,name =password,value="">
</form>
</body>
....
loinservlet.java
import java.io.*;
import javax.servlet.*;
import java.sql.*;

class Loginservlet extends HttpSevlet
{
public void dopost(HttpServletRequest request,
HttpServletResponse response)throws
ServletException,IOException
{
String connectionURL
= "jdbc:mysql://192.168.10.59/datbasename";
Connection connection=null;
ResultSet rs;
String userName=new String("");
String passwrd=new String("");
response.setContentType("text/html");
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection
(connectionURL, "root", "root");
String sql = "select user,password from User";
Statement s = connection.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
username=rs.getString("user");
passwrd=rs.getString("password");
}
rs.close ();
s.close ();
}catch(Exception e){
System.out.println("Exception is ;"+e);
}
if(userName.equals(request.getParameter("usernmae"))
&&
passwrd.equals(request.getParameter
("password"))){
out.println("User Authenticated");
}
else{
out.println("You are not an authentic person");
}
}
}
bydefault the sql run on above port but if you changed it
so please chkit and give the port nuber which you customize
Class.forname(): we pass the string of particular driver
and it automaticaly convert it inot Class object
thanks AMIT SINGH09

Is This Answer Correct ?    13 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between the prefix and postfix forms of the ++ operator?

556


Can list be final in java?

489


What is the largest data type in java?

510


What is difference between wait and notify in java?

547


What is %02d?

576






Which are different kinds of source code?

662


What one should take care of, while serializing the object?

484


What is :: operator in java?

511


What does the “final” keyword mean in front of a variable? A method? A class?

546


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

605


Does constructor return any value?

585


What types of index data structures can you have in java?

614


What is the nested interface?

599


What is final?

609


Explain different forms of polymorphism?

655