Using JAVA complete the following: Part A: Let’s begin by creating a JavaBean. C
ID: 3882481 • Letter: U
Question
Using JAVA complete the following:
Part A:
Let’s begin by creating a JavaBean. Create a User JavaBean. The User bean should have all the attributes collected from the new customer form. Also give it a username and password property.
In the NewCustomerServlet, create an instance of the User bean from the new customer form data. The username should consist of their last name combined with their zipcode. Give them a temporary password of welcome1.
Add the new create user object to the session scope.
Using EL, bind the customer object to the success page and display all the attributes along with the new username and password.
Part B:
Add a “Reset Password” link to the Login Page.
Create a password_reset.jsp
Using EL, bind the User object password to a form field in a page.
Allow the user to change their password.
On the servlet side, retrieve the user from the session and change the password to the password entered on the reset form.
Save the User object in session scope.
Redirect the user to the account_activity page.
Part C:
On the account_activity page use a JSTL if statement. If the User object is in the session and not null, display a welcome message containing their firstname and lastname in the page. If it does not exist, display a “Not Logged In” message on the page.
part D:
Implement a header.html and footer.jsp file for the header and footer of your TOBA application. Using a JSP tag, the footer should “dynamically” display the current date in the copyright information. Include the header and footer in all pages of your application.
Explanation / Answer
login.jsp
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="loginB.jsp">
<br><br>
<table align="center"><tr><td><h2>Login Authentication</h2></td></tr></table>
<table width="300px" align="center">
<tr><td colspan=2></td></tr>
<tr><td colspan=2> </td></tr>
<tr>
<td><b>Login Name</b></td>
<td><input type="text" name="uName" value=""></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" name="pswd" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr><td colspan=2> </td></tr>
</table>
</form>
</body>
</html>
loginB.jsp
<%@ page language="Java" import="java.sql.*" %>
<HTML>
<HEAD><TITLE>DataBase Search</TITLE></HEAD>
<BODY>
<jsp:useBean id="db" scope="req" class="logbean.loginB" >
<jsp:setProperty name="db" property="uName" value="<%=req.getParameter("uName")%>"/>
<jsp:setProperty name="db" property="pswd" value="<%=req.getParameter("pswd")%>"/>
</jsp:useBean>
<jsp:forward page="hello">
<jsp:param name="username" value="<%=db.getUname()%>" />
<jsp:param name="pswd" value="<%=db.getPswd()%>" />
</jsp:forward>
</body>
</html>
loginB.java
package logbean;
public class loginB {
String uName="";
String pswd="";
public String getUname() {
return uName;
}
public void setUname(String uName) {
this.uName = uName;
}
public String getPswd() {
return pswd;
}
public void setPswd(String pswd) {
this.pswd = pswd;
}
}
Log.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
public class Log extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
System.out.println("Connection Establishment");
Connection con = null;
String ull = "jdbc:mysql://localhost:3306/";
String dbn = "user_register";
String drive = "com.mysql.jdbc.Driver";
String uName = "akshay";
String pswd = "bisht";
String unmae="";
String userp="";
String query= "";
Statement st=null;
ResultSet rs=null;
HttpSession sess = req.getSession(true);
try {
Class.forName(drive).newInstance();
con = DriverManager.getConnection(ull+dbn,uName,pswd);
if(req.getParameter("unmae")!=null &&
req.getParameter("unmae")!="" && req.getParameter("pswd")!=null &&
req.getParameter("pswd")!="")
{
unmae = req.getParameter("unmae").toString();
userp = req.getParameter("pswd").toString();
query="select * from userregister where
unmae='"+unmae+"' and pswd='"+userp+"'";
System.out.println(query);
st = con.createStatement();
rs = st.executeQuery(query);
int cnt=0;
while(rs.next())
{
sess.setAttribute("unmae",rs.getString(2));
cnt++;
}
if(cnt>0)
{
res.sendRedirect("index.jsp");
}
else
{
res.sendRedirect("Log.jsp");
}
}
else
{
res.sendRedirect("Log.jsp");
}
System.out.println("Connected to the database");
con.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
index.jsp
<HTML>
<HEAD><TITLE>Welcome</TITLE></HEAD>
<BODY>
<br><br><br><br>
<table align="center">
<%
if(sess.getAttribute("unmae")!=null && sess.getAttribute("unmae")!="")
{
String user = sess.getAttribute("unmae").toString();
%>
<tr><td align="center"><h1>Welcome <b><%= user%></b></h1></td></tr>
<%
}
%>
</table>
</body>
<html>
Rate an upvote......Thankyou
Hope this helps.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.