18. Develop a Servlet to authenticate a user, where the loginid and password are available as request parameters. In case the authentication is successful, it should setup a new session and store the user's information in the session before forwarding to home.jsp, which displays the user's information like full name, address, etc.
index.jsp
<html>
<head>
<title>EX-18</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>
<body>
<div class="abc" id="f1">
<br>
<form method="POST" action="/Ex18/bipinrupadiya.blogspot.com">
<table align="center">
<tr>
<td>User Name : </td>
<td><input type="text" name="txtUsr"></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="txtPwd"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" value="Login">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
home.jsp
<html>
<head>
<title>EX-18</title>
<style>
.abc
{
background:#ababff;
position:absolute;
top:2in;
hieght:200px;
width:300px;
left:5in;
border-style:solid;
}
</style>
</head>
<body>
<%
HttpSession sessi=request.getSession();
%>
<div class="abc" id="f1">
<center>
<h1><font color="#FFFFFF">Welcome <%= session.getAttribute("sFName") %> ...!</font></h1>
<table border="1" cellPadding="5px">
<tr>
<td>Name :</td>
<td>
<%= session.getAttribute("sFName") %>
<%= session.getAttribute("sMName") %>
<%= session.getAttribute("sLName") %>
</td>
</tr>
<tr>
<td>Date of Birth :</td>
<td><%= session.getAttribute("sDOB") %></td>
</tr>
<tr>
<td>Adsress :</td>
<td><%= session.getAttribute("sAddress") %></td>
</tr>
</table>
<%session.invalidate();%>
<br>
<a href="index.jsp"> Logout </a>
</div>
</body>
</html>
Ex18.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Ex18 extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String usr=request.getParameter("txtUsr");
String pwd=request.getParameter("txtPwd");
if( usr.equals("bipin") && pwd.equals("rupadiya") )
{
String myDiv;
out.println("<html><body><form>");
myDiv="<div style='background:#ababff; position:absolute; ";
myDiv=myDiv+"top:2in; hieght:200px; width:300px;left:5in;border-style:solid'>";
out.println(myDiv);
out.println("<form><table cellpadding'2px'>");
out.println("<tr><td>First Name :</td><td><input type='text' name='txtFName' ></td></tr>");
out.println("<tr><td>MiddleName : </td><td><input type='text' name='txtMName' ></td></tr>");
out.println("<tr><td>Last Name : </td><td><input type='text' name='txtLName' ></td></tr>");
out.println("<tr><td>Date of Birth : </td><td><input type='text' name='txtDOB' ></td></tr>");
out.println("<tr><td>Address : </td><td><input type='text' name='txtAddress'></td></tr>");
out.println("<tr><td colspan='2'><input type='submit' value='OK'>");
out.println("<input type='reset' value='Clear'></td></tr>");
out.println("</td></form></div></body></html>");
}
else
{
response.sendRedirect("index.jsp");
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
HttpSession session=request.getSession();
session.setAttribute("sFName",request.getParameter("txtFName"));
session.setAttribute("sMName",request.getParameter("txtMName"));
session.setAttribute("sLName",request.getParameter("txtLName"));
session.setAttribute("sDOB",request.getParameter("txtDOB"));
session.setAttribute("sAddress",request.getParameter("txtAddress"));
response.sendRedirect("home.jsp");
}
}
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2012
(79)
-
▼
March
(7)
- 26.Develop an application to write a "page-composi...
- 27. You want to reduce the amount of Java coding i...
- 23. Develop a interest calculation application in ...
- 20. Write a JSP page, which uses the include direc...
- 19. Write a simple JSP page to display a simple me...
- 18. Develop a Servlet to authenticate a user, wher...
- 17. Develop a Servlet which looks for cookies for ...
-
▼
March
(7)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
3 comments:
I don’t have any idea about commenting on someone’s blog but it’s the first time I really want to appreciate the hard work of this blog admin for sharing this post with us.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
Spoken English Class in Anna Nagar
IELTS Coaching in T Nagar
Great Article. Thank you for sharing! Really an awesome post for every one.
Project Centers in Chennai
JavaScript Training in Chennai
Final Year Project Domains for IT
JavaScript Training in Chennai
How to see the output of your code???
Post a Comment