Hi, I have a html form where in i get values from the user, i m sending it to a servlet for validating the values entered by the user,The servlet in turn calls a EJB which interacts with the database via a procedure calls,Now my problem is if the database procedure throws some exception , it is rethrown to the servlet via the EJB and the servelt redirects it to the same html page(where the user had entered earlier).Now i have to retain all the values previously entered by the User(i Know i have to keep it in session )but let me know the better methods of where to put them in session like which place these variables have to be set
Joined: Feb 11, 2008
wanted to add one more, are there any other methods other than setting it in session
You don't need a session for this. You can catch the exception in the servlet, and then forward the request to the JSP page that generates the HTML form. Just set a request attribute that tells the JSP page that there was an error, so that it knows to repopulate the form fields with the request parameters. Most web frameworks (like Struts and Stripes) can do this for you automatically.
Thanks , But i don use jsp, i m using the same java file(servlet) to render my html page,i use place holders for displaying back to the user, but i need to retain the values to be posted back.
Joined: Mar 22, 2005
That's even easier then. If the code to create the HTML is part of the servlet, then you have access to the request object that contains all the data the user entered. So you can create an HTML page that contains those values prepopulated.
As an aside, you should seriously consider to use a JSP page instead. It's much easier to maintain, and there's no need to reload the web app upon each code change.