I have a scriptlet within my JSP page that gets an attribute "username" passed from a previous serlvet. The scriptlet validates if the "username" attribute was set, if not it denies access to homepage and instead redirects to the login page:
<%
String validUser = (String) session.getAttribute("username");
if (validUser == null){
session.setAttribute("errorMsg", "Access Denied: Please login to access this page");
session.setAttribute("username", "");
response.sendRedirect("LoginFormError.jsp");
}
%>
Since scriptlets in JSP/HTML code is not ideal, how do I go about re-writing this scriptlet as a JSTL instead?
EDIT:
Ok, so far here's what I've got:
<c:set var="validUser" value='${param.username}' />
<c:if test = "${validUser == null"}
<c:set var="errorMsg" value="${'Access Denied: Please login to access this page'}"/>
<c:set var="username" value=""/>
<c:redirect url="LoginFormError.jsp"/>
</c:if>
Are the getAttribute() and setAttribute() done right?