EDIT**
After successfully loading CSS, I encountered an issue where the page kept redirecting back to login.jsp instead of displaying the CSS. Any insights on what might be causing this?https://i.sstatic.net/Ij7Oh.png
I attempted to incorporate a custom CSS file into the header of my login.jsp page. However, upon running it, the CSS failed to load and an error message stating "too many redirects" was displayed:
too many redirects
I am unsure of how to resolve this issue.
I have made efforts to figure out how to allow CSS/JS/img files, but I lack familiarity with the web.xml
file and the recommended approach for validating those entries.
The error message states:
GET http://localhost:8080/AppV2/resource/css/login net::ERR_TOO_MANY_REDIRECTS
login.jsp page:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:include page="header.jsp" />
<link rel="stylesheet" href="resource/css/login.css">
<body>
<%
String login_msg = (String) request.getAttribute("error");
if (login_msg != null)
out.println("<font color=red size=4px>" + login_msg + "</font>");
%>
<div class = "container">
<div class="wrapper">
<form action="" method="post" name="Login_Form" class="form-signin">
<h3 class="form-signin-heading">Welcome Back! Please Sign In</h3>
<hr class="colorgraph"><br>
<input type="text" class="form-control" name="Username" placeholder="Username" required="" autofocus="" />
<input type="password" class="form-control" name="Password" placeholder="Password" required=""/>
<button class="btn btn-lg btn-primary btn-block" name="Submit" value="Login" type="Submit">Login</button>
</form>
</div>
</div>
</body>
</html>
Login.java Servlet:
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LoginServlet() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
if ((request.getParameter("password") == "") && (request.getParameter("password") == "")) {
request.setAttribute("error", "Invalid Username or Password");
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
dispatcher.forward(request, response);
} else if ((request.getParameter("password") == null) && (request.getParameter("password") == null)) {
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
dispatcher.forward(request, response);
} else {
String psw = request.getParameter("password");
String usr = request.getParameter("username");
List res = userLoginUtils.logIn(usr, psw);
Boolean debugFlag = true;
if (res.get(0).equals("true") || debugFlag == true) {
this.writeToSession(res.get(1), request);
} else {
request.setAttribute("error", "Invalid Username or Password");
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
dispatcher.forward(request, response);
}
response.sendRedirect("index");
}
}
Thanks