I have a index page of my website. it will change if user is login or not. I know how to do just by using jsp. but this is not the right way bc I am using java code in html file.

so here is ex of doing it just by jsp
index.jsp
<html>
<body>
	<%
		if (session.getAttribute("username") != null) {
			out.print("
                            <div>
                                     user | option | logout
                              </div>      
                            ");
		} else {
			out.print("
                         <div>
                              login | forgotpassword | create account
                          </div>");
		}
	%>
</body>
</html>


so I want to do the same thing only doing it by the right way(jsp/servlets). I tried look up but cant find any thing.