• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Reatining Form Values After an exception is thrown

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Albin Jose
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wanted to add one more, are there any other methods other than setting it in session
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Albin Jose
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic