Question

I am using tomcat's form based authentication for my web app. I have a login page, and login_error page, when login fails, the user is automatically sent to login error page, which displays "invalid credentials" message and gives username and password fields to login again.

All is working fine.

My problem is that how can I fill the username field with what the user entered in previous login attempt, like what happens in almost all the login forms. That is on invalid credentials, the username field retains it's value and password field is cleared. How can I do that?

Was it helpful?

Solution

I think you're looking for this:

<input name="j_username" value="<%= escape(request.getParameter('j_username')) %>" />

The implementation of the 'escape' method is left as an exercise for the reader. You probably be using some templating framework of some kind (JSTL, Velocity, Freemarker, whatever) that knows how to HTML-escape data and avoid things like double-quotes, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top