Arnab keep reading the book you will find out that the JSP can access the form parameters using scriptlets, el expressions and standard actions. Advantage of attributes is that they allow you the programmer to add (or set) programmatic (in your servlet java code) parameters. You do not have a setParameter() method out there since parameters are linked to html forms (and of course init parameters and context parameters are linked to the Deployment descriptor files).
You might even want to adjust the form parameter before dispatching it to another page and hence you can use the setAttribute() method to add your new adjusted parameter value to the request object before dispatching this to another servlet or JSP.
Joined: Jul 23, 2006
Actually the situation is I have designed a simple web app to test security. I am using the form based security, so the user-name is stored in j_username as per container requirement. Once the user logs in successfully I would like to display the user-name.
However when I use request.getParameter("j_username") it displays null. Not sure how I can save the user-name, or is there a way to add an attribute to the request object?
IF security is working, then you should be able to get the name from the Principal object that is part of the request.
Joined: Dec 19, 2006
Actually j_security_check implementation is application server specific. It's up to vendor how to implement the standard. I believe the Tomcat server creates a HttpSession but your request was not added to this session hence I dont think you can access those parameters.