Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a servlet in jsp named login servlet which checks the credentials if the password matchs or not. code is as follows: LoginServlet.java package

I have a servlet in jsp named login servlet which checks the credentials if the password matchs or not. code is as follows:

LoginServlet.java

package com.servlet;

import java.io.IOException;

import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @WebServlet("/login") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; public LoginServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String responsePage = "welcome.jsp"; String userName = request.getParameter("userName"); String password = request.getParameter("password"); String message=""; if (UserCache.users.containsKey(userName)) { User user = UserCache.users.get(userName); if (!user.getPassword().equals(password)) { responsePage="index.jsp"; message="Invalid Credentials"; }else { message=user.getName(); } } RequestDispatcher requestDispatcher = request.getRequestDispatcher(responsePage); request.setAttribute("message", message); requestDispatcher.forward(request, response); }

}

and code for jsp files i am having

-------------------------------------------index.jsp--------------------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Login

Sign In

User Name
Password
Register
<%=request.getAttribute("message")==null?"":request.getAttribute("message")%>

--------------------------------------------------------------------Register.jsp-------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Registration

Registration

Name
User Name
Password

------------------------------------------------------------welcome.jsp-------------------------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Insert title here

Welcome <%=request.getAttribute("message") %> Logout

My question is I want to add an alert using javascript if the user didn't enter any username and starts clicking on the login button. please help me where to add

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago