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)



Create a form of user Login in JSP, that accepts the user name and password from user and authentic..

Answer / 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

More Core Java Interview Questions

What is java in simple terms?

0 Answers  


What is a static class in java?

0 Answers  


real time example for deadlock,starvation,livelock

5 Answers  


Explain final, finalize() and finally?

11 Answers   Accenture, TCS,


Explain about narrowing conversion in java?

0 Answers  






what is ennumaration?

2 Answers   Amdocs,


There is a Banking application. It has 2 types of account, Savings and Current. Write a method calculateInterest by passing an ArrayList of these account objects and calculate Interest accordingly. Write code for this situation

1 Answers   ABC, KPIT,


Why are parameters used in functions?

0 Answers  


How would you use Bubble Sort to sort the number of elements?

0 Answers   Genpact,


What is the use of isempty in java?

0 Answers  


What does it mean that strings are immutable?

0 Answers  


What are the different types of sorting in java?

0 Answers  


Categories