Question
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"%>
--------------------------------------------------------------------Register.jsp-------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
------------------------------------------------------------welcome.jsp-------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started