Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create Student Login and Student Account page using HTML, CSS, JQuery and AJAX.

ID: 3567425 • Letter: C

Question

Create Student Login and Student Account page using HTML, CSS, JQuery and AJAX. Moving from "Login" to "AccountInfo" will not change the page/URL.. Successful login will take you to the Account Information screen. They must provide a unique username that is at least 6 characters. Student must provide a password that is at least 6 characters. Must provide an e-mail address that contains an "@" character. Must verify their e-mail address by typing it in again. Successful login will take you to the Account Information screen. Unsuccessful login will display error messages on the screen. Please do not give me answers from internet sites, need own code. Thanks

Explanation / Answer

loginservelet.java

import bean.LoginBean;
import dao.LoginDao;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.sql.SQLException;

/**
*
* @author English
*/
@WebServlet(urlPatterns = {"/loginservlet"})
public class loginservlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String usr=request.getParameter("userName");
String role=request.getParameter("role_name");
// System.out.println(usr);
HttpSession ss=request.getSession(true);
// String user1=new String("user1");
ss.setAttribute("user",usr);
ss.setAttribute("role",role);
  
try {
LoginBean user = new LoginBean();
// LoginBean user=(LoginBean)request.getSession().getAttribute("loginBean");
//System.out.println(user.getUserName());
user.setUserName(request.getParameter("userName"));
user.setPassword(request.getParameter("password"));
user.setRole_name(request.getParameter("role_name"));
// System.out.println(request.getParameter("designation"));

//String a1= (String)ss.getAttribute("user1");
// System.out.println("session is for "+a1);
user = LoginDao.authentication(user);
// System.out.println(user.isValid());
if (user.isValid())
{
response.sendRedirect("./Pages/Acciunts.jsp"); //logged-in page
}
else
response.sendRedirect("./Pages/error.jsp"); //logged-in page   
}
finally {
out.close();
}
}
  

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("gjhghjgfdjsfsdhfsdghf");
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("gjhghjgfdjsfsdhfsdghf");
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

Login bean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bean;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


/**
*
* @author home
*/
public class LoginBean {
  
private String userName;
private String password;
private String role_name;
private boolean valid;
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}

public String getUserName()
{
return userName;
}
  
public void setUserName(String userName)
{
this.userName=userName;
}
  
public String getPassword(){
return password;
}
public void setPassword(String password)
{
this.password=password;
}
public String getRole_name(){
return role_name;
}
public void setRole_name(String role_name)
{
this.role_name=role_name;
}

}

Login Dao

package dao;

import bean.LoginBean;
import db.DbConnect;
import java.sql.*;

/**
*
* @author home
*/
public class LoginDao {
static Statement stmt=null;
static Connection con=null;
static ResultSet rs=null,rs1=null;
public static LoginBean authentication(LoginBean bean)
{
  
String uname=bean.getUserName();
String role_name=bean.getRole_name();
String pwd=bean.getPassword();
String role_id=null;
String searchRole="select role_id from app.master_role where role_name='"+role_name+"'";
String searchQuery = "select * from app.master_user where username='" + uname + "'AND password='"+pwd+"'";

try
{
con = DbConnect.getConnection();
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
try
{
System.out.println(uname+" "+role_name+" "+pwd);
rs1=stmt.executeQuery(searchRole);
  
while(rs1.next()){
role_id=rs1.getString("role_id");
}
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
  
rs= stmt.executeQuery(searchQuery);

boolean more=rs.next();
System.out.println("raviteja "+more+" "+role_id);
if ((more)&&(!role_id.equals(rs.getString("role_id"))))
{
//System.out.println("raviteja");
bean.setValid(false);
}   
else if ((more)&&(!uname.equals(rs.getString("username"))))
{
//System.out.println("raviteja");
bean.setValid(false);
}   
else if ((more)&&(!pwd.equals(rs.getString("password"))))
{
//System.out.println("raviteja");
bean.setValid(false);
}   
  
else if(!more)
bean.setValid(false);
else
bean.setValid(true);

rs.close();
con.close();   
}catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
finally {
if (rs != null)
{
try {
rs.close();
}
catch (Exception e) {
}
rs = null;
}
if (stmt != null)
{
try {
stmt.close();
} catch (Exception e)
{}
stmt = null;
  
} if (
con != null)
{
try {
con.close();
}
catch (Exception e) { }
con = null;
}
}
  
return bean;
}
}

index.jsp

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
/* Override some defaults */
body {
background:url(bootstrap/img/business2.jpg) no-repeat ;
background-size:100%;
}
  
.container {
margin-right:40px;
width: 300px;
}
.page-header
{
background-color:white;}

/* The white background content wrapper */
.container > .content {
background-color: white;
padding: 20px;
margin: 0 -20px;
-webkit-border-radius: 10px 10px 10px 10px;
-moz-border-radius: 10px 10px 10px 10px;
border-radius: 10px 10px 10px 10px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.15);
box-shadow: 0 1px 2px rgba(0,0,0,.15);
}

   .login-form {
       margin-left: 65px;
   }
  
   /* legend {
       margin-right: -150px;
       font-weight: bold;
       color: #404040;
   }*/

   #inl
   {
   display:inline;
   }
   .btn-primary
   {
  
  
   }
   #bt
   {
   float:right;
   margin-top:-30px;
   margin-right:10px;
   }
   .heading
   {
   color:#006dcc;}
  
  
  
</style>
<script>
function validateForm()
{
var x=document.forms["myForm"]["userName"].value;
if (x==null || x=="")
{
alert("Enter username");
return false;
}


var y=document.forms["myForm"]["password"].value;
if (y==null || y=="")
{
alert("Enter password");
return false;
}
  
var z=document.forms["myForm"]["role_name"].value;
if (z==null || z=="")
{
alert("Enter designation");
return false;
}
  
  
}
</script>
</head>
<body>
  
  
<div class="page-header">
<h1 class="heading">Business</h1>
  
<button id="bt" class="btn-primary" type="submit">Sign up</button>


</div>
<div class="container">
<div class="content">
<div class="row">
<div class="login-form">
<h3 class="heading">Sign In</h3>
<form name="myForm" action="/BobApplication/loginservlet" method="post">
<fieldset>
<div class="clearfix">
<input type="text" placeholder="Username" name="userName">
</div>
<div class="clearfix">
<input type="password" placeholder="Password" name="password">
</div>
<div class="clearfix">
<select id="designation" name="role_name">
<option value='' disabled selected>Please Choose Designation</option>
<option value="business manager">Business Manager</option>
<option value="front ender">Front ender</option>
<option value="team leader">Team Leader</option>
<option value="recruiter">Recruiter</option>
<option value="vice president">Vice President</option>
</select>
</div>
<button class="btn-primary" type="submit">Sign in</button>
<br><br>
<label class="checkbox">
<input type="checkbox"> Remember me
</label>

</fieldset>
</form>
</div>
</div>
</div>
</div> <!-- /container -->

  
  
  
</body>
</html>